package test;
imp
imp
imp
imp
imp
imp
imp
imp
public class Demo2 {
/**
* @param args
*/
public static void main(String[] args)throws Exception{
Properties props=new Properties();
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.sina.com");
Session session=Session.getInstance(props,
new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("itcast_test","123456");
}
}
);
session.setDebug(true);
Message msg=new MimeMessage(session);
msg.setFrom(new InternetAddress("itcast_xxx@sina.com"));
msg.setSubject("中文主题");
msg.setContent("<span style='color:red'>中文</span>", "text/html;charset=gbk");
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("itcast_test@sina.com,itcast_test@sohu.com"));
Transport.send(msg);
}
}