-
Hi I have a usecase, where I want to automatically fetch IMAP mails from an account, but because it is auto-fetching I only want to download and process mails from permitted senders which are unread. string[] permittedSenders = // passed in via .env
var query = new SearchQuery();
foreach(var s in permittedSenders)
{
query = query.Or(SearchQuery.FromContains(s))
}
client.Inbox.Search(query.And(SearchQuery.NotSeen))
//... But apparently unseen mails only from the last permitted sender are returned. Am I missing something? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I would do something more like this: string[] permittedSenders = // passed in via .env
var query = SearchQuery.FromContains(permittedSenders[0]);
for (int i = 1; i < permittedSenders.Count; i++)
{
query = query.Or(SearchQuery.FromContains(permittedSenders[i]))
}
client.Inbox.Search(query.And(SearchQuery.NotSeen)) Keep in mind that I'm not sure why you are getting the results you are getting because to me, it would make more sense that you are getting all unseen messages. That said, the query in my example should be correct. Hopefully you get the results you are expecting. If not, I would recommend getting a protocol log (see the FAQ.md in the root of the MailKit repo) and then paste the SEARCH command here so we can see what is going on (obviously feel free to redact the email addresses). |
Beta Was this translation helpful? Give feedback.
I would do something more like this:
Keep in mind that
new SearchQuery()
is saying "ALL messages" and so the query you are using right now is "(ALL messages -OR- messages from permittedSenders[0] -OR- permittedSenders[1] ...) -AND- NotSeen"I'm not sure why you are getting the results you are getting because to me, it would make more sense that you are getting all unseen messages.
That said, the query in my exa…