谈谈关于SimpleEmail中文问题

发表于:2007-07-04来源:作者:点击数: 标签:
package mail; /** * Title:邮件 测试 * * Description: 2007.03.26 * * Copyright: Copyright (c) 2007 * * Company: * * @author not attributable * @version 1.0 */ import org.apache.commons.mail.SimpleEmail; public class SendSimpleEmail { public

package mail;

/**
 *

Title:邮件测试


 *
 *

Description: 2007.03.26


 *
 *

Copyright: Copyright (c) 2007


 *
 *

Company:


 *
 * @author not attributable
 * @version 1.0
 */
import org.apache.commons.mail.SimpleEmail;

public class SendSimpleEmail {
    public SendSimpleEmail() {
    }

    public static void main(String args[]) {
        SimpleEmail mail = new SimpleEmail();
        try {
            //设置服务类型,163邮箱为 smtp.163.com,新浪为smtp.sina.com.cn等
            mail.setHostName("smtp.163.com");
            //对发送人邮箱身份进行验证,参数一为用户名,参数二为密码
            mail.setAuthentication("用户名", "密码"); //邮箱验证
            //接收地址
            mail.addTo("xxxxx@163.com");
            //发送地址
            mail.setFrom("xxxx@163.com");
            //邮件主题
            mail.setSubject("邮件题目");
            //内容
            String str = "尊敬的客户: " + "\t\t您好!(该邮件由系统自动发送,请不要回复,谢谢。)" + "\n" +
                         "您的密码为: \n" + "\n温馨提醒:请尽快修改您的密码!";
            mail.setMsg(str);
            //为SimpleEmail设置为中文模式
            mail.setContent(str, "text/plain;charset=GBK");
            //发送
            mail.send();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

原文转自:http://www.ltesting.net