Javamail从特定发件人处获取所有电子邮件 [英] Javamail get all emails form a specific sender

查看:552
本文介绍了Javamail从特定发件人处获取所有电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在java中,我需要从特定发件人那里获取所有电子邮件。有几种方法可以做到这一点,如下所示: http://www.codejava.net/java-ee/javamail/using-javamail-for-searching-e-mail-messages

In java I need to get all emails from a specific sender. There are couple of ways to do that as shown here: http://www.codejava.net/java-ee/javamail/using-javamail-for-searching-e-mail-messages

但我需要在gmail端完成这个过程。我阅读所有电子邮件然后决定应该继续哪一个电子邮件是不合适的。

But I need to have the process to be done on gmail side. It is not fine for me to read all emails and then decide which one I should proceed.

同样在 http://alvinalexander.com/java/javamail-multiple-search-terms-pop3-mailbox-yahoo 你可以搜索邮件正文哪个好,但发件人(FROM部分)怎么样?如何过滤它?

Also in http://alvinalexander.com/java/javamail-multiple-search-terms-pop3-mailbox-yahoo you can search message body which it is great, but what about the sender (FROM part)? How can I filter it?

每次阅读所有电子邮件对我们的带宽都不利(当然,我们可以标记上次阅读的电子邮件并以某种方式阅读所有新电子邮件比如使用UIDFolder)

Also reading all emails each time is not good for our bandwidth (Of course we can mark the last read email and read just all new emails somehow like using UIDFolder)

谢谢

推荐答案

我自己找到了: )

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

SearchTerm sender = new FromTerm(new InternetAddress("from@example.com"));
Message[] messages = inbox.search(sender);

for (int i = 1; i < messages.length; i++) {
    read_message(messages[i]);
}

我需要的只是添加FromTerm!

All I needed was to add FromTerm!

这篇关于Javamail从特定发件人处获取所有电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆