我正在尝试从Spring启动应用程序发送电子邮件。这是我的配置属性。
spring:
application:
name: spring-base-template
profiles:
active: ${env:local}
mail:
default-encoding: UTF-8
host: company.host.name
username: myusername@domain.com
password: mypassword
port: 587
properties:
mail:
smtp:
auth: true
starttls:
enable: true
socketFactory:
port: 465
class: javax.net.ssl.SSLSocketFactory
fallback: false
protocol: smtp
test-connection: false
我的示例代码如下
try {
SimpleMailMessage mail = new SimpleMailMessage();
mail.setTo("myusername@domain.com");
mail.setFrom("myusername@domain.com");
mail.setSubject("Registration Confirmation");
mail.setText("You are registered Successfully! Thank you for being with us!");
javaMailSender.send(mail);
} catch(Exception e) {
e.printStackTrace();
}
当我尝试发送电子邮件时,以下是例外情况
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: company.host.name, port: 587;
nested exception is:
java.net.SocketException: Connection reset. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: company.host.name, port: 587;
nested exception is:
java.net.SocketException: Connection reset; message exception details (1)
are:
Failed message 1:
javax.mail.MessagingException: Could not connect to SMTP host:
company.host.name, port: 587;
任何想法都将不胜感激。