что я использую плохо в своем коде для получения этой ошибки:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
nested exception is:
java.net.ConnectException: Connection refused: connect. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
nested exception is:
java.net.ConnectException: Connection refused: connect; message exceptions (1) are:
Failed message 1: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
nested exception is:
java.net.ConnectException: Connection refused: connect
Я использую ApplicationConfiguration, где я определяю этот Бин:
@Bean(name = "javaMailSender")
public JavaMailSender javaMailSender(){
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
props.put("mail.smtp.username","myAddress@gmail.com");
props.put("mail.smtp.password","myPass");
Session session = Session.getInstance(props,
new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("myAddress@gmail.com", "myPass");
}
});
mailSender.setSession(session);
mailSender.setPort(587);
mailSender.setHost("smtp.gmail.com");
mailSender.setProtocol("smtp");
mailSender.setUsername("myAddress@gmail.com");
mailSender.setPassword("myPass");
return mailSender;
}
Я использую только этот код для конфигурациибоб.У кого-нибудь есть идея, чтобы решить ее?
Я пытаюсь telnet smtp.gmail.com 587, и я получаю
"220 smtp.gmail.com ESMTP 6sm10280881wrd.51 - gsmtp"