javamail发送网页邮件,且有中文

本文介绍了如何使用javamail发送包含HTML内容的邮件,以确保邮件中的链接可直接点击,并解决了中文乱码问题。关键在于设置`DataHandler`以指定`text/html;charset=gb2312`,并正确构造HTML链接,如`baidu`,避免邮箱服务解析时产生错误。
摘要由CSDN通过智能技术生成
public void sendMail() throws IOException {
	// create some properties and get the default Session
	Properties props = new Properties();
	props.put("mail.smtp.host", "smtp.sina.com.cn");
	props.setProperty("mail.smtp.auth", "true");   //这个必须加上 否则发送不了
	UserAuthenticator userAuthenticator = new UserAuthenticator("wyxz126@sina.com", "i5v2y6");
	Session session = Session.getInstance(props, userAuthenticator);
	session.setDebug(true);
	try {
	// create a message
	MimeMessage msg = new MimeMessage(session);
	msg.setFrom(new InternetAddress("wyxz126@sina.com"));
	InternetAddress[] address = {new InternetAddress(addressurl)};
	msg.setRecipients(Message.RecipientType.TO, address);
	msg.setSubject("会员注册成功 - ITeye做最棒的软件开发交流社区");
	msg.setSentDate(new Date());
	
	
	DataHandler data = new DataHandler(msgTextBuffer.toString(),"text/html;charset=gb2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值