resty mail的简单发送邮件方法
更新时间:2022年03月07日 15:37:52 作者:Dreampie
这篇文章主要为大家介绍了简单的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发送邮件的资料请关注脚本之家其它相关文章!
相关文章
IntelliJ IDEA 代码运行时中文出现乱码问题及解决方法
在我们刚接触到IDEA时,想美滋滋的敲一个“hello world”来问候这个世界,但难免会遇到这种问题乱码,这篇文章主要介绍了解决IntelliJ IDEA 代码运行时中文出现乱码问题,需要的朋友可以参考下2023-09-09
MybatisPlus3.5.5与pagehelper starter2.1.0冲突的问题解决
在使用MybatisPlus 3.5.5与PageHelper Starter 2.1.0时,由于引用了不同版本的jsqlparser库(4.6与4.7),会导致运行时错误,解决方案涉及确认依赖版本,本文就来介绍一下,感兴趣的同学可以下载学习2024-10-10


最新评论