POP3:连接到主机“ pop.163.com”的端口110,isSSL为false

时间:2019-01-22 09:32:35

标签: java email

我使用Java邮件尝试接收电子邮件,但无法连接服务器

import java.util.Properties;
import javax.mail.Address;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;

public class RecipientMail {
  public static String recipientAddress = "****@163.com";
  public static String recipientAccount = "****@163.com";
  public static String recipientPassword = "pwd";

  public static void main(String[] args) throws Exception {

    Properties props = new Properties();

    props.setProperty("mail.store.protocol", "pop3");
    props.setProperty("mail.pop3.host", "pop.163.com");
    props.setProperty("mail.host", "pop.163.com");
    Session session = Session.getInstance(props);

    session.setDebug(true);
    Store store = session.getStore("pop3");
    store.connect("pop.163.com", "****", "pwd");

    Folder folder = store.getFolder("inbox");

    folder.open(Folder.READ_WRITE);

    Message [] messages = folder.getMessages();
    for(int i = 0 ; i < messages.length ; i++){
      String subject = messages[i].getSubject();
      Address[] from = messages[i].getFrom();
      String content = (String) messages[i].getContent();
    }

    folder.close();
    store.close();
  }

}

输出:

DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]
DEBUG POP3: mail.pop3.rsetbeforequit: false
DEBUG POP3: mail.pop3.disabletop: false
DEBUG POP3: mail.pop3.forgettopheaders: false
DEBUG POP3: mail.pop3.cachewriteto: false
DEBUG POP3: mail.pop3.filecache.enable: false
DEBUG POP3: mail.pop3.keepmessagecontent: false
DEBUG POP3: mail.pop3.starttls.enable: false
DEBUG POP3: mail.pop3.starttls.required: false
DEBUG POP3: mail.pop3.finalizecleanclose: false
DEBUG POP3: mail.pop3.apop.enable: false
DEBUG POP3: mail.pop3.disablecapa: false
DEBUG POP3: connecting to host "pop.163.com", port 110, isSSL false

我发现了一件奇怪的事情: 我使用Intellj调试模式运行该程序,它显示: debug

但是商店对象的值是我的computerName@pop.163.com,而不是我声明的收件人地址的电子邮件

0 个答案:

没有答案