躺在沙滩上的小猪

快乐的每一天

javamail 一些资源..

看到几位朋友对这挺感兴趣的,整理点资料放在这里共享一下.

老本家
http://java.sun.com/products/javamail/index.jsp

developerworks 的教程 JavaMail API 基础
https://www6.software.ibm.com/developerworks/cn/education/java/j-javamail/tutorial/index.html
本地下载

JavaMail FAQ: 好东西
http://java.sun.com/products/javamail/FAQ.html


无中文困挠的使用JavaMail收取邮件
http://www.javayou.com/showlog.jspe?log_id=372

使用JavaMail的邮件发送组件
http://www.javayou.com/showlog.jspe?log_id=136


最后一个就是简化了javamail开发的。
Jakarta Commons Emails

---------------------------------------------------------------------------------
以前写的一篇介绍:
《简化JavaMail:小巧 Jakarta Commons-Email 简单教程

顺便再整理一下,朋友讨论的关于一些jakarta commons email出现乱码的问题:

一:通过SimpleEmail发送中文内容出现乱码的问题
SimpleEmail的代码如下
 1public class SimpleEmail extends Email {
 2    
/**
 3     * Set the content of the mail
 4
     *
 5     * @param
 msg A String.
 6     * @return
 An Email.
 7     * @throws
 EmailException see javax.mail.internet.MimeBodyPart
 8
     *                        for definitions
 9     * @since
 1.0
10     */

11    public Email setMsg(String msg) throws EmailException {
12        if (EmailUtils.isEmpty(msg)) 
{
13            throw new EmailException("Invalid message supplied"
);
14        }

15        setContent(msg, Email.TEXT_PLAIN);
16        return this
;
17    }

18}

只是采用默认的,

1public static final String TEXT_PLAIN = "text/plain";

并没有指定编码。

如果通过SimpleEmail发送,需要指定编码:
Water Ye@ITO 的说明
 
1email.setContent("测试邮件""text/plain;charset=GBK"); 

二:关于附件中文名称乱码的问题:

需使用MimeUtility

原因是在MIME的相应规范中(RFC2047等)说明了附件标题必须是US-ASCII字符, 所以在发送中文标题的附件时需要编码成US-ASCII字符, 有两种编码方式: B (BASE64), Q (Quoted-Printable), 这些方法在MimeUtility里
都已经做了封装, 所以在发送附件时使用如下:

1MimeUtility.encodeText(filename));


 1        EmailAttachment attachment = new EmailAttachment();
 2        attachment.setPath("c:\\测试.txt"
);
 3
        attachment.setDisposition(EmailAttachment.ATTACHMENT);
 4        attachment.setDescription("测试文件"
);
 5        

 6           //
 7
        attachment.setName(MimeUtility.encodeText("测试文件.txt"));
 8

 9         MultiPartEmail email = new
 MultiPartEmail();
10        email.setHostName("192.168.0.3"
);
11        email.setAuthentication("martin.xus""1234"
);
12        email.addTo("martin.xus@192.168.0.3""martin"
);
13        email.setFrom("martin.xus@192.168.0.3""martin"
);
14

15        email.setSubject("测试带附件"
);
16        email.setMsg("该邮件含附件"
);
17        //添加附件

18        email.attach(attachment);
19        //发送邮件

20        email.send();


end
---------------------------------------------------------------------------------

我想这些资源已经足够 o_o

你还想知道什么:)

posted on 2005-10-10 19:21 martin xus 阅读(431) 评论(0)  编辑  收藏 所属分类: java