java - javax.mail.MessagingException:连接失败;如何解决这个问题?
问题描述
这是我的代码。...
Properties properties = new Properties();
properties.put("mail.pop3.host", host);
properties.put("mail.pop3.port", "995");
properties.put("mail.pop3.starttls.enable", "true");
properties.put("mail.pop3.ssl.enable", "false");
properties.put("mail.pop3.starttls.required", "true");
Session emailSession = Session.getDefaultInstance(properties);
//create the POP3 store object and connect with the pop server
try {
store = emailSession.getStore("pop3s");
} catch (NoSuchProviderException e) {
e.printStackTrace();
}
try {
store.connect(host, username, password);
} catch (MessagingException e) {
e.printStackTrace();
}
...
这在我的本地机器上工作。当我部署到服务器时,这向我显示了一个错误。
'''
javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:218)
at javax.mail.Service.connect(Service.java:366)
at javax.mail.Service.connect(Service.java:246)
at com.objectone.aws_demo.config.EmailConfiguration.config(EmailConfiguration.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
at org.springframework.beans.factory.support.Constructor
...
如何解决这个问题?我有 telnet 到 telnet pop.gmail.com 995。telnet 也可以工作。
解决方案
推荐阅读
- javascript - 根据不同依赖项获取数据的最佳 useEffect-setup
- discord.py - Discord bot 不返回角色成员
- java - 获取自 Java 9 以来使用的 JRE 的供应商
- julia - 精确线搜索算法
- php - 为什么 PHP $_SESSION 不能在其他页面上运行?
- reactjs - 将 React 客户端与 Heroku 上的 Flask socket.io 服务器连接起来
- ajax - 在 codeigniter 中使用 ajax 打印获取的数据
- android - 如何在android 11中检测指纹硬件
- python - 在 Python 中,当一列具有大量的分类唯一值时,首选哪个图?
- elixir - 如何通过手动调用在生产中运行自定义任务?