resty mail的簡單發送郵件方法

1. 配置MailPlugin插件

public void configPlugin(PluginLoader pluginLoader) {
    MailPlugin mailPlugin = new MailPlugin();
    pluginLoader.add(mailPlugin);
}

2. 發送普通的文本郵件

//方法1
SimpleEmail simpleEmail=MailSender.getSimpleEmail("測試主題","測試內容","[email protected]");
simpleEmail.send();

//方法2
MailSender.sendText("測試主題","測試內容","[email protected]");

3. 發送html郵件

//方法1
HtmlEmail htmlEmail = MailSender.getHtmlEmail("測試", "[email protected]");
//String cid1 = htmlEmail.embed(new File(圖片文件地址1), "1");
//String cid2 = htmlEmail.embed(new File(圖片文件地址2), "2");
//發送圖片在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. 發送附件郵件

//附件設置
EmailAttachment attachment =new EmailAttachment();  
attachment.setPath("c:/234.jpg");// 本地文件  
// attachment.setURL(new URL("http://xxx/a.gif"));//遠程文件  
attachment.setDisposition(EmailAttachment.ATTACHMENT);  
attachment.setDescription("a.jpg");  
attachment.setName("a.jpg");  
//方法1
MultiPartEmail multiPartEmail=MailSender.getMultiPartEmail("測試主題","測試內容",attachment,"[email protected]");
multiPartEmail.send();

//方法2
MailSender.sendAttachment("測試主題","測試內容",attachment,"[email protected]");

以上就是resty mail的簡單發送郵件方法的詳細內容,更多關於resty mail發送郵件的資料請關註WalkonNet其它相關文章!

推薦閱讀: