50,531
社区成员
发帖
与我相关
我的任务
分享
import javax.mail.PasswordAuthentication;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Message.RecipientType;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Demon2 {
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("cherryfun","cherry");
}
}
);
session.setDebug(true);
Message msg=new MimeMessage(session);
msg.setRecipients(RecipientType.TO,
InternetAddress.parse("cherryfun@sina.com,272640074@qq.com"));
msg.setFrom(new InternetAddress("lili@sina.com"));
msg.setSubject("o o ");
msg.setContent("<span style:color='red'>你是我的唯一</span>", "text/html;charset=gbk");
Transport.send(msg);
}
}