java文本域 图片_用java如何实现 在文本框中显示图片

展开全部

下面是可以运行32313133353236313431303231363533e59b9ee7ad9431333337393533的例子:public void  testImageMail(){

//创建和环境有关的Session对象.  该session对象中包含了连接邮件服务器的地址.. 端口.. 协议

Properties  properties = new Properties();

//指定发送的协议

properties.setProperty("mail.transport.protocol", "smtp");

//指定邮件服务器的地址

properties.setProperty("mail.host", "127.0.0.1");

//通过javamail发送邮件的时候,会把具体的发送命令打印出来

properties.setProperty("mail.debug", "true");

Session  session = Session.getDefaultInstance(properties);

//创建一个代表一封邮件的Message对象

Message  message = new MimeMessage(session);

//设置发件人...

try {

message.setFrom(new  InternetAddress("xxxxxx"));

/** BCC:密送CC:抄送To:发送 */

message.setRecipient(RecipientType.TO, new InternetAddress("xxxxxx"));

//设置邮件的主题

message.setSubject("这是一个简单的邮件");

Multipart  multipart = new MimeMultipart("mixed");

//创建一个装显示图片的html

MimeBodyPart  html = new MimeBodyPart();

//要使用cid来指定具体的资源id

 html.setContent("", "text/html");

//创建一个图片的mimebodypart

MimeBodyPart  image = new MimeBodyPart();

//将一个图片做具体的数据出过来

image.setDataHandler(new DataHandler(new FileDataSource(new File("F:\\xxx.gif"))));

image.setContentID("xxxxxxx");

multipart.addBodyPart(html);

multipart.addBodyPart(image);

//设置一个复杂类型的邮件内容

message.setContent(multipart);

//可以通过Session对象找得到发送对象Transport...

Transport  transport = session.getTransport();

//通过发送对象去连接邮件服务器... 提供链接服务器的用户名而不是邮件的地址,不带@符号的

transport.connect("xxxxxx", "xxxxxx");

//连接上后发送邮件(Message),发送给指定的地址

transport.sendMessage(message, message.getAllRecipients());

//关闭连接

transport.close();

} catch (Exception e) {

e.printStackTrace();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值