[JAVA]jodd-mail java發送接收電子郵件

今天剛剛看到有這個工具包就先使用了了一下java

個人需求就是發送系統通知服務器

而後就去官網變學習邊使用這裏順便記錄一下session

先上maven地址maven

<dependency>
    <groupId>org.jodd</groupId>
    <artifactId>jodd-mail</artifactId>
    <version>3.6.5</version>
</dependency>

我使用的是騰訊的企業郵箱全部發送郵件的服務器是smtp 通過SSL加密的 465端口工具

import jodd.mail.Email;
import jodd.mail.SendMailSession;
import jodd.mail.SmtpServer;
import jodd.mail.SmtpSslServer;
public class MailTest {
	public static void main(String args[]){
		SmtpServer<?> smtp = SmtpSslServer.create("smtp.exmail.qq.com",465);//設置SSL的smtp服務器
		smtp.authenticateWith("youremailname@xxx.com", "xxxxxx");
		SendMailSession session = smtp.createSession();
		Email email = Email.create().from("youremailname@xxx.com")
				.to("target@xxx.com").subject("主題")//設置了主題
				.addHtml("<p style='background:red'>第四回答是</p>")
				;
		session.open();//打開鏈接
		session.sendMail(email);//發送郵件
		session.close();//關閉鏈接
	}
}

    用着簡單官網上也都有例子
學習

相關文章
相關標籤/搜索