服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Java教程 - resty mail的简单发送邮件方法

resty mail的简单发送邮件方法

2022-09-01 10:37Dreampie Java教程

这篇文章主要为大家介绍了简单的resty mail发送邮件方法示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步早日升职加薪

1. 配置MailPlugin插件

?
1
2
3
4
public void configPlugin(PluginLoader pluginLoader) {
    MailPlugin mailPlugin = new MailPlugin();
    pluginLoader.add(mailPlugin);
}

2. 发送普通的文本邮件

?
1
2
3
4
5
6
//方法1
SimpleEmail simpleEmail=MailSender.getSimpleEmail("测试主题","测试内容","[email protected]");
simpleEmail.send();
 
//方法2
MailSender.sendText("测试主题","测试内容","[email protected]");

3. 发送html邮件

?
1
2
3
4
5
6
7
8
9
//方法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. 发送附件邮件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
//附件设置
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发送邮件的资料请关注服务器之家其它相关文章!

原文链接:https://dreampie.gitbooks.io/resty-chs/content/mail.html

延伸 · 阅读

精彩推荐