好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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='HdhCmsTestdreampie.cn'>Dreampie</a>" );

htmlEmail.send();

//方法2  不能像方法1通过cid在html中嵌入图片 直接写图片链接可能会被过滤掉

MailSender.sendHtml( "测试主题" , "<a href='HdhCmsTestdreampie.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

查看更多关于resty mail的简单发送邮件方法的详细内容...

  阅读:12次