发送邮件(@163.com)
来源:互联网 发布:俄罗斯域名注册商 编辑:程序博客网 时间:2024/06/06 00:03
1.添加依赖,
commons-email 等等
@Test
public void sendMail() throws EmailException, MalformedURLException, UnsupportedEncodingException {//可以添加发送响应的类
HtmlEmail email = new HtmlEmail();
//HostName的配置
email.setHostName("smtp.163.com");
//发送文件的邮箱地址
email.setSSLOnConnect(true);
//接收文件的邮箱地址
email.addTo("16910735@qq.com", "");
//发送文件的邮箱及密码
email.setSubject("账号激活");
email.setCharset("UTF-8");
// embed the image and get the content id
URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
String cid = email.embed(url, "Apache logo");
// set the html message
String content="<html><meta charset=\"utf-8\" />" +
"账号激活地址:<a href='http://localhost:8080/user/xxxxxxxxxxxx'>http://localhost:8080/user/xxxxxxxxxxxx</a>"+
"</html>";
email.setHtmlMsg(new String(content.getBytes(),"UTF-8"));
// set the alternative message;文件的内容
email.setTextMsg("此邮件不需要回复");
// send the email;确认发送
email.send();}
阅读全文