无法使用Mail API使用searchTerm搜索电子邮件服务器 [英] Not able to search the email server with searchTerm using Mail API

查看:592
本文介绍了无法使用Mail API使用searchTerm搜索电子邮件服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从一封电子邮件gg@gg.com发送一封电子邮件,其中包含2个电子邮件ID的附件.一个是我的电子邮件ID,另一个是xx@xx.com 我收到了那封电子邮件.当我使用带有电子邮件ID作为搜索标准的Java Mail API进行邮件搜索时,虽然我收到了该电子邮件,但无法找到它.但是当我将其转发到同一电子邮件ID的搜索条件时,它工作正常.请让我知道何时首次收到电子邮件,为什么它无法搜索

An email is sent from lets say gg@gg.com with an attachment to 2 email id's .One, my email id and another xx@xx.com I got that email. When i did mail search using java Mail API with email id as search criteria , it is not able to find it though i received that email.But when i forward it to the same email id's search criteria is working fine. Please let me know when email is received for the first time at that point why it is not able to search

Properties properties = System.getProperties();
        properties.put("mail.smtp.host", ExchangeProperties.getSmtpHost());
        properties.put("mail.pop3.connectiontimeout", String.valueOf(ExchangeProperties.getPop3ConnectionTimeout() * 1000));
        properties.put("mail.pop3.timeout", String.valueOf(ExchangeProperties.getPop3Timeout() * 1000));
        session = Session.getInstance(properties, null);
        session.setDebug(logger.isDebugEnabled());
        // Get the store
        store = session.getStore("pop3");
        store.connect(ExchangeProperties.getSmtpHost(), user, password);


 Folder folder = store.getFolder(folderName)
      Message[] foundMessages  = folder.search(andTerm); //andTerm contains email id
      FetchProfile fp = new FetchProfile();
                    fp.add(FetchProfile.Item.ENVELOPE);
                    folder.fetch(foundMessages, fp);

推荐答案

由于您使用的是pop3,因此所有搜索都是通过将所有消息下载到客户端并在其中进行搜索来完成的.如果要服务器进行搜索,请使用imap.

Since you're using pop3, all the searching is done by downloading all the messages to the client and searching them there. If you want the server to do the searching, use imap.

如果在打开pop3文件夹的同时收到新消息,则将无法看到它.您需要关闭文件夹并重新打开它.那是pop3协议的局限性.

If the new message arrives while you have the pop3 folder open, you won't be able to see it. You need to close the folder and reopen it. That's a limitation of the pop3 protocol.

如果这些方法都不能解决您的问题,那么我需要确切地知道您使用的是哪个搜索字词,您要搜索的值是什么,以及电子邮件标题中出现的值是什么.

If none of that helps with your problem, I would need to know exactly which search term you're using, exactly what value you're searching for, and exactly what value appears in the email header.

这篇关于无法使用Mail API使用searchTerm搜索电子邮件服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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