Apache Commons Email邮件发送
来源:互联网 发布:小米床垫怎么样 知乎 编辑:程序博客网 时间:2024/05/19 22:55
1、Commons Email将javamail封装了,方便使用。只需要引入以下pom.xml
<!-- mail --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-email</artifactId> <version>1.4</version> </dependency>
2、发送简单的文本
SimpleEmail email = new SimpleEmail(); email.setHostName("xxxx.com"); email.setAuthentication("xxx.com", "***");//邮件服务器验证:用户名/密码 email.setCharset("UTF-8");// 必须放在前面,否则乱码 email.addTo("xxx.com");//收件人 email.setFrom("xxx.com", "xxx"); email.setSubject("subject中文"); email.addCc("抄送人邮箱"); email.setMsg("msg中文"); email.send();
3、发送带附件的邮件
MultiPartEmail email = new MultiPartEmail(); email.setHostName("xxx.com"); email.setAuthentication("xxx.com", "***"); email.setCharset("UTF-8"); email.addTo("xxxl.com"); email.setFrom("xxx.com", "support"); email.setSubject("subject中文"); email.setMsg("msg中文"); EmailAttachment attachment = new EmailAttachment(); attachment.setPath("d:/a.gif");// 本地文件 // attachment.setURL(new URL("http://xxx/a.gif"));//远程文件 attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("abc"); attachment.setName("abc"); email.attach(attachment); email.send();
4、发送HTML格式邮件
HtmlEmail email = new HtmlEmail(); email.setHostName("xxx.com"); email.setAuthentication("xxx.com", "***"); email.setCharset("UTF-8"); email.addTo("xxx.com"); email.setFrom("xxx.com", "support"); email.setSubject("标题"); email.setHtmlMsg("<b>测试内容</b>"); email.send();
5、偌需要通过代理来发送邮件
SimpleEmail email = new SimpleEmail(); email.setHostName("xxxx.com"); email.setAuthentication("xxx.com", "***");//邮件服务器验证:用户名/密码 email.setCharset("UTF-8");// 必须放在前面,否则乱码 email.addTo("xxx.com");//收件人 email.setFrom("xxx.com", "xxx"); email.setSubject("subject中文"); email.addCc("抄送人邮箱"); email.setMsg("msg中文"); Properties properties = System.getProperties(); properties.setProperty("socksProxyHost",代理服务器的地址); properties.setProperty("socksProxyPort",代理服务器的端口号); email.send();
0 0
- Apache-commons-email发送邮件
- Apache Commons Email邮件发送
- 使用Apache Commons-email组件发送邮件
- 使用Apache Commons-email组件发送邮件
- 利用Apache commons-email组件发送邮件
- apache commons-email发送邮件乱码问题
- 利用Apache Commons Email发送邮件
- 利用apache commons-email发送邮件
- Commons: 封装Apache Commons Email简化邮件发送
- commons-email 发送邮件
- 通过apache 的 commons-email 包发送邮件
- 采用apache的commons-email包发送邮件死锁
- 用 apache commons-email 轻松发送无乱码邮件
- 通过commons-email发送邮件
- 使用commons email发送邮件
- Commons-Email收发邮件[apache]
- JAVA APACHE EMAIL 发送邮件
- commons-email 轻松发送无乱码邮件
- sqlserver安装设置小计
- 蓝桥杯——算法训练 求指数(Vip试题)
- VS开发Application生硬古怪的问题及原因汇总
- JS隐藏div占用与不占用页面位置方法
- go reflect
- Apache Commons Email邮件发送
- 信号处理——信号频域变换
- HTML5中 audio标签的样式修改
- Postman用法简介-Http请求模拟工具
- Python3.6安装以及numpy库、matplotlib库的安装方法(Win7)
- 快速傅立叶变换(FFT)的一种推导
- 学生信息管理系统(jdbc操作MySQL)
- 文章标题
- linux下svn使用小结 创建 添加仓库 版本管理