2017-06-06 99 views
0

我无法配置Spring和Sendmail一起工作。Spring Boot Sendmail

弹簧侧:

的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 /邮件/访问

Connect:localhost.localdomain   RELAY 
Connect:localhost      RELAY 
Connect:127.0.0.1      RELAY 

的/ etc /邮件/本地主机名

mydomain.com 

的/ etc /邮件/的virtusertable

[email protected] noreply 

(我有作为用户添加noreply)

我没有得到任何错误。没有日志。没有发送电子邮件。我如何配置它?

回答

0

默认情况下,Spring Boot中的某些超时值是无限的。 尝试按照建议的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(...);

+0

它解决了,但我切换回Gmail后。 10倍 –