1. 程式人生 > 其它 >蘋果Mac測試及維護工具:​​​​​​​​Techtool Pro

蘋果Mac測試及維護工具:​​​​​​​​Techtool Pro

<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
	<groupId>javax.mail</groupId>
	<artifactId>mail</artifactId>
	<version>1.5.0-b01</version>
</dependency>
public static void sendJMToolMail(String subject,String text) throws Exception {
	String myEmailAccount = "[email protected]"; // 發件人郵箱地址
	String myEmailPassword = "swmecxxxxxxrbjfd"; // 發件人郵箱密碼
	String myEmailSMTPHost = "smtp.qq.com"; // 發件人郵箱伺服器協議
	String senderPersonalName = "JMTool上線告警助手"; // 發件人暱稱
	String receiveMailAccount = "ivan.xxxx.com"; //收件人郵箱陣列
	String mailTransportProtocol = "smtp"; // 使用的協議(JavaMail規範要求)
	Properties props = new Properties();
	props.setProperty("mail.transport.protocol", mailTransportProtocol);
	props.setProperty("mail.smtp.host", myEmailSMTPHost);   // 發件人的郵箱的 SMTP 伺服器地址
	props.setProperty("mail.smtp.auth", "true");            // 需要請求認證
	Session session = Session.getInstance(props);
	session.setDebug(false);
	MimeMessage message = new MimeMessage(session);
	message.setFrom(new InternetAddress(myEmailAccount, senderPersonalName, "UTF-8"));
	Address[] internetAddressTo = InternetAddress.parse(receiveMailAccount);
	message.setRecipients(MimeMessage.RecipientType.TO, internetAddressTo);
	message.setSubject(subject, "UTF-8");
	message.setContent(text, "text/html;charset=UTF-8");
	message.setSentDate(new Date());
	message.saveChanges();
	Transport transport = session.getTransport();
	transport.connect(myEmailAccount, myEmailPassword);
	transport.sendMessage(message, message.getAllRecipients());
	transport.close();
}
public static void main(String[] args) throws Exception {
	sendJMToolMail("JMTOOL主題","JMTOOL告警測試");
}