gpt4 book ai didi

java - 如何使用 Java 代码阅读 MS Outlook 收件箱邮件?

转载 作者:行者123 更新时间:2023-12-01 05:07:35 24 4
gpt4 key购买 nike

我需要使用java代码从Outlook收件箱中读取主题、消息。是否有相同的示例代码/想法,请帮助获得相同的内容。

我用StackOverflow搜索,它给出了C#代码。

我还检查了 Javamail,但没有找到任何有关 Outlook 的信息。

最佳答案

我就是这样做的。

   /**
* Connects to email server with credentials provided to read from a given
* folder of the email application
*
* @param username Email username (e.g. janedoe@email.com)
* @param password Email password
* @param server Email server (e.g. smtp.email.com)
* @param INBOX Folder in email application to interact with
* @throws Exception
*/
public OutlookEmail() throws Exception {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imap");
props.setProperty("mail.imap.ssl.enable", "true");
props.setProperty("mail.imaps.partialfetch", "false");
props.put("mail.mime.base64.ignoreerrors", "true");

Session mailSession = Session.getInstance(props);
mailSession.setDebug(true);
Store store = mailSession.getStore("imap");
store.connect("outlook.office365.com", "YOUREMAILADDRESS", "YOUR PASSWORD");


Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);

System.out.println("Total Message:" + folder.getMessageCount());
System.out.println("Unread Message:" + folder.getUnreadMessageCount());

messages = folder.getMessages();

for (Message mail : messages) {



System.out.println("*********************************");
System.out.println("MESSAGE : \n");

System.out.println("Subject: " + mail.getSubject());
System.out.println("From: " + mail.getFrom()[0]);
System.out.println("To: " + mail.getAllRecipients()[0]);
System.out.println("Date: " + mail.getReceivedDate());
System.out.println("Size: " + mail.getSize());
System.out.println("Flags: " + mail.getFlags());
System.out.println("ContentType: " + mail.getContentType());
System.out.println("Body: \n" + getEmailBody(mail));
System.out.println("*******************************");

}
}

**从配置中读取并传递凭据、uname、pwd 作为参数并进行屏蔽。

关于java - 如何使用 Java 代码阅读 MS Outlook 收件箱邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12482640/

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