1:jar包
2:设置你自己的授权码,去你发件邮箱,设置授权码,不会的百度。
3: 代码
多种模式发送邮件,举个例子如下。
public static void main(String[] args) throws Exception{
// Create the email message
HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.163.com");
email.setAuthentication("ning17610910315@163.com","*************");
email.addTo("ning17610910315@163.com", "Json");
email.setFrom("ning17610910315@163.com", "json");
email.setSubject("Test email with inline image");
// 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
email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>");
// set the alternative message
email.setTextMsg("Your email client does not support HTML messages");
// send the email
email.send();
}