podczas wysyłania wiadomości otrzymuję ten błądnie można połączyć się z hostem SMTP: smtp.gmail.com, Port: 465, odpowiedzi: -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
mojego kodu jest:
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);
Każda pomoc będzie doceniona.
Dzięki z góry.
Sprawdź http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/ – Abi
Próbowałem tego samego kodu, ale nadal m uzyskanie błąd: javax.mail.MessagingException : 530 5.7.0 Musi najpierw wydać komendę STARTTLS. 4sm28216799pbn.23 - gsmtp \t na com.sun.mail.smtp.SMTPTransport.issueCommand (SMTPTransport.java:1020) w com.sun.mail.smtp.SMTPTransport.mailFrom (SMTPTransport.java:716) \t na com. sun.mail.smtp.SMTPTransport.sendMessage (SMTPTransport.java:388) \t at rapid.mail.main (mail.java:60) Ta linia dla starttls jest wtedy, dlaczego m otrzymuje ten sam błąd: properties.put ("mail .smtp.starttls.enable "," true "); – user1900376
Wypróbuj najnowszą wersję JAR JavaMail 1.4.7 – Abi