首页 > 解决方案 > 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 也可以工作。

标签: javaemailjakarta-mail

解决方案


推荐阅读