java 发送邮件昵称_javaMail发送邮件设置发件人中文昵称

转:http://blog.csdn.net/mengxianhua/article/details/7406960

public class TextMessage {

//发送信件邮箱的用户名及密码

static String username="272138576";

static String password="********";

public static void main(String [] args)throws Exception{

String from="272138576@qq.com";

String to="zousy999@qq.com";

String subject="test";

String body="test!!!";

Properties props = System.getProperties();

// 创建信件服务器

props.put("mail.smtp.host", "smtp.qq.com");

props.put("mail.smtp.auth", "true");

props.put("mail.transport.protocol", "smtp");

// 得到默认的对话对象

Authenticator a = new Authenticator() {

public PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(username, password);

}

};

//创建Session实例

Session session = Session.getDefaultInstance(props, a);

//创建MimeMessage实例对象

MimeMessage msg=new MimeMessage(session);

//设置发信人

//msg.setFrom(new InternetAddress(from));

//设置自定义发件人昵称

String nick="";

try {

nick=javax.mail.internet.MimeUtility.encodeText("我的昵称");

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

}

msg.setFrom(new InternetAddress(nick+" "));

//设置收信人

msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));

//设置发送日期

msg.setSentDate(new Date());

//设置邮件主题

msg.setSubject(subject);

//设置邮件正文

msg.setText(body);

Transport.send(msg);

}

}

InternetAddress from = new InternetAddress("xxx@xxx.com", "我的昵称");

有 带昵称的构造函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值