gpt4 book ai didi

java - 在 Java 中通过 Pop3 读取 Outlook 365 的收件箱时遇到错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:17 25 4
gpt4 key购买 nike

我需要从 Outlook 365 帐户的收件箱文件夹中读取电子邮件。我已经安装了所有必需的证书,并且能够从我的计算机远程登录 outlook.office365.com 主机。

我使用的是 JDK 1.6.0.29 版本,我的 outlook 365 对 POP3 和 IMAP 使用 TLS 1.0 加密。

但我仍然遇到错误 -

javax.mail.AuthenticationFailedException: EOF on socket
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:209)
at javax.mail.Service.connect(Service.java:386)
at client.ConnectToOffice365REST.check(ConnectToOffice365REST.java:56)
at client.ConnectToOffice365REST.main(ConnectToOffice365REST.java:96)

这是我的完整代码-

package client;




import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;

public class ConnectToOffice365REST{
public static String username =null;
public static String password1 =null;
public static void check(String host, String storeType, String user,
String password)
{ username= user;
password1 = password;
try {



//create properties field
Properties properties = new Properties();

properties.put("mail.pop3.host", host);
properties.put("mail.pop3.port", "995");
properties.put("mail.pop3.starttls.enable", "true");
properties.setProperty("mail.pop3.socketFactory.fallback", "false");
properties.setProperty("mail.pop3.socketFactory.port",
String.valueOf("995"));
properties.put("mail.pop3.auth", "true");
properties.put("mail.debug.auth", "true");
Session emailSession = Session.getDefaultInstance(properties);





//create the POP3 store object and connect with the pop server

Store store = emailSession.getStore("pop3");
// store.connect(host, user, password);
// store.connect(host, 995, user, password);

//create the folder object and open it
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);

// retrieve the messages from the folder in an array and print it
Message[] messages = emailFolder.getMessages();
System.out.println("messages.length---" + messages.length);

for (int i = 0, n = messages.length; i < n; i++) {
Message message = messages[i];
System.out.println("---------------------------------");
System.out.println("Email Number " + (i + 1));
System.out.println("Subject: " + message.getSubject());
System.out.println("From: " + message.getFrom()[0]);
System.out.println("Text: " + message.getContent().toString());

}

//close the store and folder objects
emailFolder.close(false);
store.close();

} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {

String host = "outlook.office365.com";// change accordingly
String mailStoreType = "pop3";
String username = "username";// change accordingly
String password = "password";// change accordingly

check(host, mailStoreType, username, password);

}

}

请告诉我问题出在哪里。1)我必须安装更多证书吗?2)用户名和密码完全没问题。3) 这是因为 TLS 而不是 SSL 加密吗?

我尝试用谷歌搜索这个错误,但没有找到确切的根本原因?

提前致谢!

最佳答案

我终于取得了突破,我已经在我的论坛中发布了所有必需的步骤http://kushalkariaofm.blogspot.in/2017/03/how-to-read-emails-from-inbox-folder_28.html

关于java - 在 Java 中通过 Pop3 读取 Outlook 365 的收件箱时遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42978499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com