Spring 启动 Sendmail
Spring Boot Sendmail
我无法配置 Spring 和 Sendmail 一起工作。
Spring 边:
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
application.properties
spring.mail.protocol=smtp
spring.mail.host=localhost
spring.mail.port=25
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.smtp.auth=false
spring.mail.properties.mail.smtp.starttls.enable=false
发送邮件代码(适用于 gmail)
@Async
@Override
public void sendActivationEmail(String username, String activationToken) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(username);
message.setSubject(EmailUtils.EMAIL_ACTIVATION_SUBJECT);
message.setText(String.format(EmailUtils.EMAIL_ACTIVATION_BODY, activationToken));
this.javaMailSender.send(message);
}
Linux 边:
/etc/mail/access
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
/etc/mail/local-host-names
mydomain.com
/etc/mail/virtusertable
noreply@mydomain.com noreply
(我已经添加 noreply 为用户)
我没有收到任何错误。日志中没有任何内容。也没有发送电子邮件。我该如何全部配置?
某些超时值在 Spring 默认情况下是无限的。
尝试按照建议将超时值设置为合理的值in the documentation,看看是否超时。
spring.mail.properties.mail.smtp.connecttimeout=5000
spring.mail.properties.mail.smtp.timeout=3000
spring.mail.properties.mail.smtp.writetimeout=5000
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-email.html
同时设置发件人地址:
message.setFrom(...);
我无法配置 Spring 和 Sendmail 一起工作。
Spring 边:
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
application.properties
spring.mail.protocol=smtp
spring.mail.host=localhost
spring.mail.port=25
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.smtp.auth=false
spring.mail.properties.mail.smtp.starttls.enable=false
发送邮件代码(适用于 gmail)
@Async
@Override
public void sendActivationEmail(String username, String activationToken) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(username);
message.setSubject(EmailUtils.EMAIL_ACTIVATION_SUBJECT);
message.setText(String.format(EmailUtils.EMAIL_ACTIVATION_BODY, activationToken));
this.javaMailSender.send(message);
}
Linux 边:
/etc/mail/access
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
/etc/mail/local-host-names
mydomain.com
/etc/mail/virtusertable
noreply@mydomain.com noreply
(我已经添加 noreply 为用户)
我没有收到任何错误。日志中没有任何内容。也没有发送电子邮件。我该如何全部配置?
某些超时值在 Spring 默认情况下是无限的。 尝试按照建议将超时值设置为合理的值in the documentation,看看是否超时。
spring.mail.properties.mail.smtp.connecttimeout=5000
spring.mail.properties.mail.smtp.timeout=3000
spring.mail.properties.mail.smtp.writetimeout=5000
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-email.html
同时设置发件人地址:
message.setFrom(...);