亲宝软件园·资讯

展开

resty mail发送邮件

Dreampie 人气:0

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]");

加载全部内容

相关教程
猜你喜欢
用户评论