预览加载中,请您耐心等待几秒...
1/2
2/2

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

1、在我的资源库里面下载支持的jar包,下载地址:http://download.csdn.net/detail/harderxin/4451541 2、测试代码: packagecom.email.test; importjava.util.Properties; importjavax.mail.Address; importjavax.mail.Message; importjavax.mail.Session; importjavax.mail.Transport; importjavax.mail.internet.InternetAddress; importjavax.mail.internet.MimeMessage; publicclassTestEmail{ publicvoidSendEmailTest(){ Propertiesprops=newProperties(); props.put("mail.smtp.host","smtp.qq.com"); props.put("mail.smtp.auth","true");//允许smtp校验 SessionsendMailSession=Session.getInstance(props,null); try{ Transporttransport=sendMailSession.getTransport("smtp"); //连接你的QQ,注意用户名和密码必须填写正确,否则权限得不到 transport.connect("smtp.qq.com","3693352@qq.com","****"); MessagenewMessage=newMimeMessage(sendMailSession); //设置mail主题 Stringmail_subject="更改邮件发送人测试"; newMessage.setSubject(mail_subject); //设置发信人地址 StringstrFrom="517122199@qq.com"; strFrom=newString(strFrom.getBytes(),"iso-8859-1"); newMessage.setFrom(newInternetAddress(strFrom)); //AddressaddressFrom[]={new(参考:http://www.linbayan8.com) //InternetAddress("617334015@qq.com"),new //InternetAddress("goodnight0002@163.com")}; //改变发件人地址 //newMessage.addFrom(addressFrom); //设置收件人地址 AddressaddressTo[]={newInternetAddress("306220165@qq.com")}; newMessage.setRecipients(Message.RecipientType.TO,addressTo); //设置mail正文 newMessage.setSentDate(newjava.util.Date()); Stringmail_text="java实现邮件发送!"; newMessage.setText(mail_text); newMessage.saveChanges();//保存发送信息 transport.sendMessage(newMessage,newMessage .getRecipients(Message.RecipientType.TO));//发送邮件 transport.close(); //Transport.send(newMessage); System.out.println("发送成功!"); }catch(Exceptione){ System.out.println("发送失败!"); System.out.println(e); } } publicst