如何使用Java代码读取MS Outlook收件箱邮件?

3

我需要使用Java代码从Outlook的收件箱中读取主题和消息。是否有任何示例代码/想法可以做到这一点,请帮助我获得相同的内容。

我在StackOverflow上搜索,它提供了C#代码。

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


http://stackoverflow.com/questions/4780870/ideas-about-linux-based-solutions-for-parsing-email-storage-files-of-ms-outlook - user1728950
3个回答

1
这是我的做法。
   /**
 * 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("*******************************");          

    }
}

从配置文件中读取信息,并将凭据、用户名和密码作为参数传递并进行屏蔽。

0
如果想使用Java读取.pst文件可能不是一个好选择。对我来说,如果你有服务器详情,直接从服务器获取邮件更有意义。
我从Google得到了这个link--“读取pst文件”。

0
当你说“Outlook的收件箱”时,你是指Outlook存储在本地计算机上的数据吗?还是指远程邮件服务器中的收件箱邮件文件夹中的数据,可能是Exchange?如果是后者,你可以使用JavaMail来完成,但你必须配置Exchange服务器以允许IMAP访问。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接