resty mail的簡單發(fā)送郵件方法
更新時間:2022年03月07日 15:37:52 作者:Dreampie
這篇文章主要為大家介紹了簡單的resty mail發(fā)送郵件方法示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪
1. 配置MailPlugin插件
public void configPlugin(PluginLoader pluginLoader) {
MailPlugin mailPlugin = new MailPlugin();
pluginLoader.add(mailPlugin);
}
2. 發(fā)送普通的文本郵件
//方法1
SimpleEmail simpleEmail=MailSender.getSimpleEmail("測試主題","測試內(nèi)容","[email protected]");
simpleEmail.send();
//方法2
MailSender.sendText("測試主題","測試內(nèi)容","[email protected]");3. 發(fā)送html郵件
//方法1
HtmlEmail htmlEmail = MailSender.getHtmlEmail("測試", "[email protected]");
//String cid1 = htmlEmail.embed(new File(圖片文件地址1), "1");
//String cid2 = htmlEmail.embed(new File(圖片文件地址2), "2");
//發(fā)送圖片在htmlMsg里加上這個 <img src="cid:" + cid1 + "\"'/><img src=\"cid:" + cid2 + ""'/>
htmlEmail.setHtmlMsg("<a href='www.dreampie.cn'>Dreampie</a>");
htmlEmail.send();
//方法2 不能像方法1通過cid在html中嵌入圖片 直接寫圖片鏈接可能會被過濾掉
MailSender.sendHtml("測試主題","<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("測試主題","測試內(nèi)容",attachment,"[email protected]");
multiPartEmail.send();
//方法2
MailSender.sendAttachment("測試主題","測試內(nèi)容",attachment,"[email protected]");以上就是resty mail的簡單發(fā)送郵件方法的詳細(xì)內(nèi)容,更多關(guān)于resty mail發(fā)送郵件的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Spring項(xiàng)目集成RabbitMQ及自動創(chuàng)建隊列
這篇文章主要介紹了Spring項(xiàng)目集成RabbitMQ及自動創(chuàng)建隊列,本文內(nèi)容分別在Spring(V5.2.6)和Spring Boot(V2.5.14)兩個項(xiàng)目中經(jīng)過了驗(yàn)證,需要的朋友可以參考下2024-02-02
IntelliJ?IDEA?代碼運(yùn)行時中文出現(xiàn)亂碼問題及解決方法
在我們剛接觸到IDEA時,想美滋滋的敲一個“hello?world”來問候這個世界,但難免會遇到這種問題亂碼,這篇文章主要介紹了解決IntelliJ?IDEA?代碼運(yùn)行時中文出現(xiàn)亂碼問題,需要的朋友可以參考下2023-09-09
MybatisPlus3.5.5與pagehelper?starter2.1.0沖突的問題解決
在使用MybatisPlus?3.5.5與PageHelper?Starter?2.1.0時,由于引用了不同版本的jsqlparser庫(4.6與4.7),會導(dǎo)致運(yùn)行時錯誤,解決方案涉及確認(rèn)依賴版本,本文就來介紹一下,感興趣的同學(xué)可以下載學(xué)習(xí)2024-10-10
關(guān)于@ComponentScan注解的用法及作用說明
這篇文章主要介紹了關(guān)于@ComponentScan注解的用法及作用說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-09-09

