Не удалось подключиться к SMTP-узлу: smtp.gmail.com, порт: 465, ответ: -1.JAVA

Программисты JAVA общаются здесь
Anonymous
Не удалось подключиться к SMTP-узлу: smtp.gmail.com, порт: 465, ответ: -1.

Сообщение Anonymous »

При отправке почты я получаю следующую ошибку:

java.lang.RuntimeException: javax.mail.SendFailedException: Отправка
не удалась; вложенное исключение: класс javax.mail.MessagingException:
Не удалось подключиться к SMTP-узлу: smtp.gmail.com, порт: 465, ответ: -1

Вот мой код:

Код: Выделить всё

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);
// ...
}
В чем причина этой ошибки и как ее решить?


Подробнее здесь: https://stackoverflow.com/questions/153 ... response-1

Вернуться в «JAVA»