Я пытаюсь отправить почту с помощью mail.smtp.yahoo.com в JavaОтправить почту с помощью javax.mail через Yahoo в Java
Вот мой код для отправки почты:
final String Username = "*****************";
final String Password = "*****************";
String to = "*****************";
String host = "smtp.mail.yahoo.com";
Properties properties = System.getProperties();
// Setup mail server
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.user", Username);
properties.put("mail.smtp.password", Password);
properties.put("mail.smtp.port", "587");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
try {
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(Username));
// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
to));
// Set Subject: header field
message.setSubject("This is the Subject Line!");
// Now set the actual message
message.setText("This is actual message");
// Send message
Transport transport = session.getTransport("smtp");
transport.connect(host, Username, Password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
System.out.println("Sent message successfully....");
} catch (MessagingException mex) {
mex.printStackTrace();
}
Я получаю эту ошибку:
avax.mail.MessagingException: Could not connect to SMTP host: smtp.mail.yahoo.com, port: 587;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1706)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at MailHelper.main(MailHelper.java:51)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at sun.security.ssl.InputRecord.handleUnknownRecord(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:503)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:234)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1672)
... 4 more
Я попытался отправить его с помощью порта 25,465 также, но безрезультатно. Я также попытался отправить его с помощью smtp.gmail.com и gmail userid и пройти, но получить разные ошибки.
Пожалуйста, помогите
Я думаю, что вам не хватает 'properties.put (" java.net.preferIPv4Stack "," true "); ' –
Пробовал это. Но получаю такую же ошибку. Я создал приложение Java и запускаю это приложение локально. DO Мне нужно добавить любую конфигурацию для этого? @HelpingHands –
У вас есть какой-либо брандмауэр или что-то установленное? –