JAVAMAIL和Gmail的POP3 SSL(Javamail and Gmail Pop3 SS

2019-06-24 00:21发布

我想要我的应用程序连接到Gmail检查电子邮件。 我必须使用SSL POP3的。

这是我的代码:

    Properties props = new Properties();

    props.put("mail.host", "pop.gmail.com");
    props.put("mail.store.protocol", "pop3s");
    props.put("mail.pop3s.auth", "true");
    props.put("mail.pop3s.port", "993");

    Session session = Session.getDefaultInstance(props, null);
    Store store=session.getStore();
    store.connect("myuser@gmail.com","mypass");

而我得到这个错误:

Exception in thread "main" javax.mail.MessagingException: Connect failed;
  nested exception is:
    java.io.IOException: Unexpected response: * OK Gimap ready for requests from x.x.x.x.x z50if25691877wef.13
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:210)
    at javax.mail.Service.connect(Service.java:295)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:196)

我认为这具有良好的新:回答Gmail服务器,但是......似乎在JavaMail的一个坏的方式来回答。

Answer 1:

端口应该是995的Gmail: http://support.google.com/mail/bin/answer.py?hl=en&answer=13287



Answer 2:

我认为这会帮助你

 Properties properties = new Properties();  
 properties.put("mail.pop3.host", pop3Host);
 properties.put("mail.pop3.ssl.enable", true);
 properties.put("mail.pop3.ssl.trust", "*");
 properties.put("mail.pop3.port", 995);
 Session emailSession = Session.getDefaultInstance(properties); `enter code here`


文章来源: Javamail and Gmail Pop3 SSL