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("/file/upload/202211/13/edjnsurodcp.jpg"));//远程文件
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发送邮件的资料请关注编程网其它相关文章!