我面临无法发送电子邮件的事实。我不明白原因。我使用 Spting Boot 2。该示例使用 JavaMailSender 类。但是你可以不用它的实现和在 application.properties 中指定的必要参数吗?
@Configuration
public class MainConfiguration {
@Bean
public JavaMailSender getJavaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.yandex.ru");
mailSender.setPort(465);
mailSender.setUsername("test@yandex.ru");
mailSender.setPassword("test122223");
Properties props = mailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
//props.put("mail.smtp.timeout", 1000);
return mailSender;
}
@Bean
public SimpleMailMessage templateSimpleMessage() {
SimpleMailMessage message = new SimpleMailMessage();
message.setText("This is the test email template for your email:");
return message;
}
}
2 分钟后,出现错误:"javax.mail.MessagingException: Could not connect to SMTP host"
侃侃无极
江户川乱折腾
相关分类