阅读背景:

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

来源:互联网 
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("[email protected]", "i5v2y6");
	Session session = Session.getInstance(props, userAuthenticator);
	session.setDebug(true);
	try {
	// create a message
	MimeMessage msg = new MimeMessage(session);
	msg.setFrom(new InternetAddress("[email protected]"));
	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=gb2312"); //这是发送的是网页形式并且有中文
	msg.setDataHandler(data);
	// send the message
	Transport.send(msg);
	
	} catch (MessagingException mex) {
	mex.printStackTrace();
	Exception ex = null;
	if ((ex = mex.getNextException()) != null) {
	ex.printStackTrace();
	}
	}
	}public void sendMail() throws IOException {
	//



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: