使用Apache Commons-email发送电子邮件
所需要的jar包
- commons-emai-1.2.jar
- commons-logging-1.1.1.jar
- mail.jar
如果JDK版本过低还需要
发送简单邮件
@Test
public void sendSimpleMail() throws Exception {
SimpleEmail email = new SimpleEmail();
email.setHostName("smtp.gmail.com"); // 发送服务器
email.setAuthentication("gaowm0207@gmail.com", "password"); // 发送邮件的用户名和密码
email.addTo("459978392@qq.com", "a"); // 接收邮箱
email.setFrom("gaowm0207@163.com", "a"); // 发送邮箱
email.setSubject("测试主题");// 主题
email.setMsg("这里是邮件内容"); // 内容
email.setSmtpPort(465); // 端口
email.setSSL(true); // gmail需要设置SSL安全设置
email.setCharset("GBK"); // 编码
email.send();
}
谷歌邮件服务的发送邮件端口不是默认的25,而是465,所以需要在代码中设置
发送带有附件的邮件
@Test
public void sendMutiMail() throws Exception{
EmailAttachment attachment = new EmailAttachment();
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("python resource");
attachment.setPath("src/com/beckham/common/email/附件.txt");
//attachment.setURL(new URL("http://xxx/a.gif"));//远程文件
attachment.setName(MimeUtility.encodeText("附件.txt")) ; //设置附件的中文编码
MultiPartEmail email = new MultiPartEmail();
email.setHostName("smtp.163.com"); // 发送服务器
email.setAuthentication("gaowm0207@163.com", "password"); // 发送邮件的用户名和密码
email.addTo("459978392@qq.com", "a"); // 接收邮箱
email.setFrom("gaowm0207@163.com", "a"); // 发送邮箱
email.setSubject("测试主题");// 主题
email.setMsg("这里是邮件内容"); // 内容
email.setCharset("GBK"); // 编码
// 添加附件
email.attach(attachment);
// 发送邮件
email.send();
}
发送Html格式的邮件
public void sendHtmlMail() throws Exception {
HtmlEmail email = new HtmlEmail();
email.setHostName("mail.fastunit.com");
email.setAuthentication("support@fastunit.com", "***");
email.setCharset("UTF-8");
email.addTo("fastunit.com@hotmail.com");
email.setFrom("support@fastunit.com", "support");
email.setSubject("subject中文");
email.setHtmlMsg("<b>msg中文</b>");
email.send();
}
官方演示
分享到:
相关推荐
赠送jar包:commons-email-1.5.jar; 赠送原API文档:commons-email-1.5-javadoc.jar; 赠送源代码:commons-email-1.5-sources.jar; 赠送Maven依赖信息文件:commons-email-1.5.pom; 包含翻译后的API文档:...
基于Java调用邮件系统所需要的jar包,commons-email-1.5.jar,javax.mail-1.4.5.jar,activation.jar
1)将文件放入libs后,在gradle文件里加入implementation files('libs/commons-email-1.5.jar') 2)android收发邮件会要求引入此jar包
jar包大小:135KB commons-validator-1.3.1.jar jar包大小:93KB commons-transaction-1.2.jar jar包大小:141KB commons-scxml-0.6.jar jar包大小:254KB commons-primitives-1.0.jar jar包大小:60KB commons-pool-1.3....
集成邮件发送所需要的四个jar包,activation.jar、additionnal.jar、commons-email-1.4.jar、mail.jar
commons-email-1.5-src.zip 借助commons-email简化发送邮件的过程
commons-email-1.4.jarcommons-email-1.4.jarcommons-email-1.4.jar
开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2...
邮件开发包,email包,是开发web常用包
activation.jar commons-email-1.2.jar mail.jar免费下载
commons-logging-1.0-javadoc.jar, commons-logging-1.0.1-javadoc.jar, commons-logging-1.0.1.jar, commons-logging-1.0.2-javadoc.jar, commons-logging-1.0.2.jar, commons-logging-1.0.3-javadoc.jar, commons-...
Java发送邮件所需要的几个JAR包,打包发给大家,包含以下内容: commons-email-1.1.jar mail.jar additionnal.jar activation.jar
赠送jar包:commons-email-1.5.jar; 赠送原API文档:commons-email-1.5-javadoc.jar; 赠送源代码:commons-email-1.5-sources.jar; 赠送Maven依赖信息文件:commons-email-1.5.pom; 包含翻译后的API文档:...
NULL 博文链接:https://liangq.iteye.com/blog/1222307
包含邮件发送的jar包,同时添加实现过程文章的连接,个人觉着操作简单,可以轻松实现邮件发送功能。啦啦啦啦啦啦啦啦啦
commons-beanutils-1.8.0-bin.zip commons-collections-3.2.1-bin.zip ...commons-email-1.1-bin.zip commons-fileupload-1.2.1-bin.zip commons-io-1.4-bin.zip commons-lang-2.4-bin.zip commons-net-1.4.1.zip
赠送jar包:commons-net-3.8.0.jar; 赠送原API文档:commons-net-3.8.0-javadoc.jar; 赠送源代码:commons-net-3.8.0-sources.jar; 赠送Maven依赖信息文件:commons-net-3.8.0.pom; 包含翻译后的API文档:...
commons-email-1.2 api 说明
commons-email-1.4
常用jar包下载,包括commons-beanutils-1.9.3、commons-collections-3.2.2、commons-collections4-4.1