问题描述
我有一个带有javamail的spring boot应用程序,我配置了spring.properties,但似乎没有属性来发送电子邮件。
#mail properties
spring.mail.host = smtp.gmail.com
spring.mail.port = 587
spring.mail.username = [email protected]
spring.mail.password = eeee
spring.mail.protocol = smtp
spring.mail.defaultEncoding=UTF-8
spring.mail.smtp.starttls.enable=false
spring.mail.smtp.starttls.required=false
spring.mail.smtp.auth=true
spring.mail.smtp.connectiontimeout=5000
spring.mail.smtp.timeout=5000
spring.mail.smtp.writetimeout=5000
此处为发送电子邮件的Java代码
@Service
public class MailSenderServiceImpl implements IMailSenderService{
@Autowired
JavaMailSender mailSender;
@Override
public void sendEmailStatusNotification(Shipment shipment) throws IOException,MessagingException{
final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage,"UTF-8");
message.setFrom(shipment.getSender().getSenderEmail());
message.setTo(new String[] {shipment.getRecipient().getRecipientEmail()});
message.setSubject("Shipment "+shipment.getTrackingNumber()+"status update");
message.setText("the shipment status is now :"+shipment.getStatus().getLabel());
this.mailSender.send(mimeMessage);
}
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
我们在这里看到此错误
org.springframework.mail.MailSendException:邮件服务器连接失败;嵌套的异常是com.sun.mail.util.MailConnectException:无法连接到主机,端口:localhost,25;超时-1; 嵌套的异常是: java.net.ConnectException:连接被拒绝:连接。失败消息:com.sun.mail.util.MailConnectException:无法连接到主机,端口:localhost,25;超时-1; 嵌套的异常是: java.net.ConnectException:连接被拒绝:connect;消息异常(1)是: 失败的消息1:com.sun.mail.util.MailConnectException:无法连接到主机,端口:localhost,25;超时-1; 嵌套的异常是: java.net.ConnectException:连接被拒绝:connect
有什么主意吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)