khi gửi thư tôi nhận được lỗi nàyKhông thể kết nối đến máy chủ SMTP: smtp.gmail.com, cổng: 465, phản ứng: -1
java.lang.RuntimeException: javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
mã của tôi là:
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("email","password");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("email"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(this.to));
message.setSubject("Testing");
message.setText("Hey, this is the testing email.");
Transport.send(message);
Bất kỳ trợ giúp sẽ được đánh giá cao.
Cảm ơn trước.
Kiểm tra http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/ – Abi
Tôi đã thử cùng một mã nhưng vẫn nhận được lỗi: javax.mail.MessagingException : 530 5.7.0 Phải phát hành một lệnh STARTTLS trước. 4sm28216799pbn.23 - gsmtp \t tại com.sun.mail.smtp.SMTPTransport.issueCommand (SMTPTransport.java:1020) tại com.sun.mail.smtp.SMTPTransport.mailFrom (SMTPTransport.java:716) \t tại com. sun.mail.smtp.SMTPTransport.sendMessage (SMTPTransport.java:388) \t tại rapid.mail.main (mail.java:60) Dòng này cho starttls là có thì tại sao m nhận được lỗi tương tự: properties.put ("mail .smtp.starttls.enable "," true "); – user1900376
Hãy thử dùng phiên bản jar mới nhất JavaMail 1.4.7 – Abi