码迷,mamicode.com
首页 > Web开发 > 详细

Apache-SimpleEmail 简单应用

时间:2016-09-11 20:02:56      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

比JavaMail使用方法要直接,jar包只需要在JavaMail的基础上添加commons-email-1.4.jar即可。

代码:

// QQ邮箱发送邮件
SimpleEmail simpleEmail = new SimpleEmail();
simpleEmail.setHostName("smtp.qq.com");
simpleEmail.setAuthentication("3******8", "g*****ai");
simpleEmail.setSmtpPort(587);
simpleEmail.setFrom("3********@qq.com", "y****", "UTF-8");
simpleEmail.addTo(email, name);
simpleEmail.setSubject("title");
simpleEmail.setMsg("content");
simpleEmail.send();
					    
System.out.println("发送邮件成功!");

 

// 网易邮箱发送邮件
SimpleEmail simpleEmail = new SimpleEmail();
simpleEmail.setHostName("smtp.163.com");
simpleEmail.setAuthentication("y*******@163.com", "y********");
simpleEmail.setSmtpPort(25);
simpleEmail.setFrom("y*******@163.com", "y*", "UTF-8");
simpleEmail.addTo("3**********@qq.com", "c**************");
simpleEmail.setSubject("网易邮箱测试");
simpleEmail.setMsg("网易邮箱测试网易邮箱测试网易邮箱测试");
simpleEmail.send();
System.out.println("发送成功");

 

// 发送带附件的邮件
// 附件
EmailAttachment attachment = new EmailAttachment();
attachment.setPath("D:\\testEXC.xlsx");
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("excel文件");
attachment.setName("MyExcel.xlsx");
// 邮件
MultiPartEmail simpleEmail = new MultiPartEmail();
simpleEmail.setHostName("smtp.163.com");
simpleEmail.setAuthentication("y***********@163.com", "y********");
simpleEmail.setSmtpPort(25);
simpleEmail.setFrom("y*********@163.com", "y*", "UTF-8");
simpleEmail.addTo("3**************@qq.com", "c***********");
simpleEmail.setSubject("带附件");
simpleEmail.setMsg("带附件的邮件测试");
simpleEmail.attach(attachment);
simpleEmail.send();
System.out.println("发送成功");

  

Apache-SimpleEmail 简单应用

标签:

原文地址:http://www.cnblogs.com/loveflycforever/p/5862389.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!