javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered(such as ssl)
Properties prop = new Properties();
prop.setProperty("mail.transport.protocol", "smtp"); // 設置郵件發(fā)送協(xié)議
prop.setProperty("mail.host", "smtp.qq.com"); // 郵件服務器地址
//prop.setProperty("mail.smtps.ssl.enable", "true"); // 郵件ssl驗證
prop.setProperty("mail.smtp.auth", "true"); // 郵件服務身份驗證
//prop.setProperty("mail.smtp.localhost", "127.0.0.1");
Session session = Session.getDefaultInstance(prop);
// 收件人電子郵箱
String to = "xxxxx@qq.com";
// 發(fā)件人電子郵箱
String from = "xxxx@qq.com";
try{
// 創(chuàng)建默認的 MimeMessage 對象
MimeMessage message = new MimeMessage(session);
// Set From: 頭部頭字段
message.setFrom(new InternetAddress(from));
// Set To: 頭部頭字段
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set Subject: 頭部頭字段
message.setSubject("This is the Subject Line!");
// 設置消息體
message.setText("This is actual message");
// 根據(jù) Session 獲取郵件傳輸對象
Transport transport = session.getTransport();
transport.connect("xxx@qq.com","xxxxx");
// 發(fā)送消息
transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
1 回答

喵喔喔
TA貢獻1735條經驗 獲得超5個贊
服務器要求加密,你卻注釋掉了
//prop.setProperty("mail.smtps.ssl.enable", "true"); // 郵件ssl驗證
添加回答
舉報
0/150
提交
取消