首页 > 代码库 > Apache-SimpleEmail 简单应用
Apache-SimpleEmail 简单应用
比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 简单应用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。