我设置端口587作为recomended在我的应用程序.propertys,但springboot似乎仍然使用端口25尽管,有人能告诉我为什么端口25不工作,或者更重要的是我如何修复我的smtp端口587?提前感谢!
错误类型:
2023-12-18T15:30:19.084+01:00 ERROR 15800 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.mail.MailSendException: Mail server connection failed. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect; message exceptions (1) are:
Failed message 1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect] with root cause
java.net.ConnectException: Connection refused: connect
at java.base/sun.nio.ch.Net.connect0(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.connect(Net.java:579) ~[na:na]
at java.base/sun.nio.ch.Net.connect(Net.java:568) ~[na:na]
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:585) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:633) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:583) ~[na:na]
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:361) ~[jakarta.mail-1.1.0.jar:na]
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236) ~[jakarta.mail-1.1.0.jar:na]
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2209) ~[jakarta.mail-1.1.0.jar:na]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:754) ~[jakarta.mail-1.1.0.jar:na]
at jakarta.mail.Service.connect(Service.java:342) ~[jakarta.mail-1.1.0.jar:na]
at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:518) ~[spring-context-support-6.0.12.jar:6.0.12]
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:437) ~[spring-context-support-6.0.12.jar:6.0.12]
字符串
我代码:
@Component
public class EmailSender {
@Bean
public static JavaMailSenderImpl javaMailSender() {
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setProtocol("SMTP");
javaMailSender.setHost("smtp.office365.com");
javaMailSender.setPort(587);
return javaMailSender;
}
JavaMailSender mailSender = new JavaMailSenderImpl();
public void sendEmail(String to, String subject, String message){
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(to);
mailMessage.setSubject(subject);
mailMessage.setText(message);
mailSender.send(mailMessage);
}
}
型
我的应用程序。
# mail
#spring.mail.host=smtp-mail.outlook.com
spring.mail.host=smtp.office365.com
spring.mail.properties.mail.transport.protocol=smtp
spring.mail.port=587
spring.mail.username=${[email protected]}
spring.mail.password=${*secret*}
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.debug=true
型
我试图在我的应用程序中发送电子邮件,但在端口25处出现错误,而我已设置smtp端口587
迎接
1条答案
按热度按时间vxqlmq5t1#
https://stackoverflow.com/a/38629240/23120849
这是一个很好的工作!它工作。
当然,对于Outlook的端口和主机:
example.put(“mail.smtp.host“,“smtp.office365.com“);
public String s(“String s”);