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
javamail发送网页邮件,且有中文
最新推荐文章于 2021-08-13 21:10:46 发布
本文介绍了如何使用javamail发送包含HTML内容的邮件,以确保邮件中的链接可直接点击,并解决了中文乱码问题。关键在于设置`DataHandler`以指定`text/html;charset=gb2312`,并正确构造HTML链接,如`<a href='//www.baidu.com'>baidu</a>`,避免邮箱服务解析时产生错误。
摘要由CSDN通过智能技术生成