简体   繁体   English

Java错误javax.mail.MessagingException:无法连接到SMTP主机:

[英]Java error javax.mail.MessagingException: Could not connect to SMTP host:

I have a java application which sends email.It have been working well never had this problem. 我有一个发送电子邮件的Java应用程序。它运行良好,从未遇到过这个问题。 Suddenly today I see a lot of these error, but there are some which went through successfully.Below is the full trace. 今天突然我看到了很多这样的错误,但是还是成功地解决了一些。下面是完整的跟踪。

javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
java.net.ConnectException: Connection timed out
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at commServer9000$MailProcessor.run(commServer9000.java:6550)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
    ... 8 more

In this case, enabling SSL solved my problem. 在这种情况下,启用SSL解决了我的问题。

JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.gmail.com");
mailSender.setPort(465);

//setting username and password
mailSender.setUsername("UserName");
mailSender.setPassword("Password");

//setting Spring JavaMailSenderImpl Properties
Properties mailProp = mailSender.getJavaMailProperties();

mailProp.put("mail.transport.protocol", "smtp");
mailProp.put("mail.smtp.auth", "true");
mailProp.put("mail.smtp.starttls.enable", "true");
mailProp.put("mail.smtp.starttls.required", "true");
mailProp.put("mail.debug", "true");
mailProp.put("mail.smtp.ssl.enable", "true");
mailProp.put("mail.smtp.user", String.valueOf(resourceList.get(0)));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javax.mail.MessagingException:无法连接到SMTP主机? - javax.mail.MessagingException: Could not connect to SMTP host? 发送邮件错误,javax.mail.MessagingException:无法连接到SMTP主机:本地主机,端口:25; - Sending mail error, javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; 通过Java发送电子邮件-javax.mail.MessagingException:无法连接到SMTP主机:localhost,端口:587; - Sending emails through Java - javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 587; javax.mail.MessagingException:无法连接到SMTP主机:smtp.gmail.com,端口:587; java.net.NoRouteToHostException:主机没有路由 - javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587; java.net.NoRouteToHostException: No route to host java.lang.RuntimeException:javax.mail.MessagingException:无法连接到SMTP主机:smtp.gmail.com,端口:465 - java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465 javax.mail.MessagingException:无法连接到 SMTP 主机:smtp.gmail.com,端口:465; - javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465; javax.mail.MessagingException:无法连接到 SMTP 主机:smtp.gmail.com,端口:587 - javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587 javax.mail.MessagingException:无法连接到SMTP主机:<主机名>端口:25响应:554 - javax.mail.MessagingException: Could not connect to SMTP host : <host name> port : 25 response: 554 如何解决 java.net.SocketException:Connection reset。 失败的消息:javax.mail.MessagingException:无法连接到 SMTP 主机 - How to resolve java.net.SocketException:Connection reset. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host javax.mail.MessagingException:无法连接到SMTP主机:103.12.134.112,端口:25; - javax.mail.MessagingException: Could not connect to SMTP host: 103.12.134.112, port: 25;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM