package com.email;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.MultiPartEmail;
import org.apache.commons.mail.SimpleEmail;
public class test1 {
public static void main(String[] args) throws EmailException, MalformedURLException {
// Email email = new SimpleEmail();
// email.setHostName("smtp.qq.com");
// email.setSmtpPort(465);
// email.setAuthenticator(new DefaultAuthenticator("[email protected]", "fqiullgsbiqhdeha"));
// email.setSSLOnConnect(true);
// email.setCharset("UTF-8");
// email.setFrom("[email protected]","asdasd");
// email.addTo("[email protected]");
//
// email.setSubject("TestMail");
// email.setMsg("你好,This is a test mail ... :-)");
// email.send();
// email.send();
HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.qq.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("[email protected]", "fqiudsddhdeha"));
email.setSSLOnConnect(true);
email.setCharset("UTF-8");
email.setFrom("[email protected]","云稅通");
email.addTo("[email protected]");
email.setSubject("測驗HTML郵件"); // 主題
URL url = new URL("http://5b0988e595225.cdn.sohucs.com/images/20190522/c302a3ce10eb4e3aa872aba4ae1df302.png");
String cid = email.embed(url, "Apache logo");
email.setHtmlMsg("<html>這里是測驗HTML郵件內容:<br><br>"
+ "http://5b0988e595225.cdsn.sohucs.com/images/20200522/c302a3casd1df302.png"
+ "<br><br><img src=https://bbs.csdn.net/"cid:" + cid
+ "\"><br><br>------------------------------------------------------<br><br>"
+ "聯 系 人:舒<br><br>聯系電話:13811111111<br><br>"
+ "公司地址:高新區16層6號<br><br>"
+ "公司網址:http://www.tcadxsgo.cn"
+ "<br><br>------------------------------------------------------</html>"); // 發送內容
email.send();
System.out.println("Success!");
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/117451.html
標籤:Java EE
