Java 发邮件
public class SendEmail2 {
/**
*
*
*/
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.163.com");
Session session = Session.getDefaultInstance(props,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("uyikuy54@163.com", "dfw678631");
}
});
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("uyikuy54@163.com"));
msg.setSubject("hello");
msg.setRecipients(RecipientType.TO, InternetAddress.parse("54354526@qq.com"));
msg.setContent("<a style='color: #ef027c;' href='http://www.naver.com'>韩国网站</a>", "text/html;charset=utf-8");
Transport.send(msg);
}