resty mail的簡(jiǎn)單發(fā)送郵件方法
1. 配置MailPlugin插件
public void configPlugin(PluginLoader pluginLoader) {
MailPlugin mailPlugin = new MailPlugin();
pluginLoader.add(mailPlugin);
}
2. 發(fā)送普通的文本郵件
//方法1
SimpleEmail simpleEmail=MailSender.getSimpleEmail("測(cè)試主題","測(cè)試內(nèi)容","[email protected]");
simpleEmail.send();
//方法2
MailSender.sendText("測(cè)試主題","測(cè)試內(nèi)容","[email protected]");3. 發(fā)送html郵件
//方法1
HtmlEmail htmlEmail = MailSender.getHtmlEmail("測(cè)試", "[email protected]");
//String cid1 = htmlEmail.embed(new File(圖片文件地址1), "1");
//String cid2 = htmlEmail.embed(new File(圖片文件地址2), "2");
//發(fā)送圖片在htmlMsg里加上這個(gè) <img src="cid:" + cid1 + "\"'/><img src=\"cid:" + cid2 + ""'/>
htmlEmail.setHtmlMsg("<a href='www.dreampie.cn'>Dreampie</a>");
htmlEmail.send();
//方法2 不能像方法1通過cid在html中嵌入圖片 直接寫圖片鏈接可能會(huì)被過濾掉
MailSender.sendHtml("測(cè)試主題","<a href='www.dreampie.cn'>Dreampie</a>","[email protected]")4. 發(fā)送附件郵件
//附件設(shè)置
EmailAttachment attachment =new EmailAttachment();
attachment.setPath("c:/234.jpg");// 本地文件
// attachment.setURL(new URL("http://xxx/a.gif"));//遠(yuǎn)程文件
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("a.jpg");
attachment.setName("a.jpg");
//方法1
MultiPartEmail multiPartEmail=MailSender.getMultiPartEmail("測(cè)試主題","測(cè)試內(nèi)容",attachment,"[email protected]");
multiPartEmail.send();
//方法2
MailSender.sendAttachment("測(cè)試主題","測(cè)試內(nèi)容",attachment,"[email protected]");以上就是resty mail的簡(jiǎn)單發(fā)送郵件方法的詳細(xì)內(nèi)容,更多關(guān)于resty mail發(fā)送郵件的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Java開發(fā)必備知識(shí)之?dāng)?shù)組詳解
數(shù)組對(duì)于每一門編程語言來說都是重要的數(shù)據(jù)結(jié)構(gòu)之一,當(dāng)然不同語言對(duì)數(shù)組的實(shí)現(xiàn)及處理也不盡相同.本篇文章為大家整理了Java最全關(guān)于數(shù)組的知識(shí)點(diǎn),并給出其對(duì)應(yīng)的代碼,需要的朋友可以參考下2021-06-06
Spring項(xiàng)目集成RabbitMQ及自動(dòng)創(chuàng)建隊(duì)列
這篇文章主要介紹了Spring項(xiàng)目集成RabbitMQ及自動(dòng)創(chuàng)建隊(duì)列,本文內(nèi)容分別在Spring(V5.2.6)和Spring Boot(V2.5.14)兩個(gè)項(xiàng)目中經(jīng)過了驗(yàn)證,需要的朋友可以參考下2024-02-02
關(guān)于JDBC的簡(jiǎn)單封裝(實(shí)例講解)
下面小編就為大家?guī)硪黄P(guān)于JDBC的簡(jiǎn)單封裝(實(shí)例講解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08
IntelliJ?IDEA?代碼運(yùn)行時(shí)中文出現(xiàn)亂碼問題及解決方法
在我們剛接觸到IDEA時(shí),想美滋滋的敲一個(gè)“hello?world”來問候這個(gè)世界,但難免會(huì)遇到這種問題亂碼,這篇文章主要介紹了解決IntelliJ?IDEA?代碼運(yùn)行時(shí)中文出現(xiàn)亂碼問題,需要的朋友可以參考下2023-09-09
MybatisPlus3.5.5與pagehelper?starter2.1.0沖突的問題解決
在使用MybatisPlus?3.5.5與PageHelper?Starter?2.1.0時(shí),由于引用了不同版本的jsqlparser庫(4.6與4.7),會(huì)導(dǎo)致運(yùn)行時(shí)錯(cuò)誤,解決方案涉及確認(rèn)依賴版本,本文就來介紹一下,感興趣的同學(xué)可以下載學(xué)習(xí)2024-10-10
關(guān)于@ComponentScan注解的用法及作用說明
這篇文章主要介紹了關(guān)于@ComponentScan注解的用法及作用說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09

