javax.mail.MessagingException:连接失败;如何解决这个问题?

时间:2019-10-27 16:42:04

标签: java email javamail

这是我的代码。 ...

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也可以。

0 个答案:

没有答案