Hi All,
I want to find/search for all unread emails received the last 24 hours and have a sender domain like “@example.com” or “@example2.org”
The received emails may come from different domains and only a couple of them are to be searched. Therefore, I would like to read an excel sheet with domains to be searched so I need to have a dynamic filter. How is the best way to do this?
Lets say my xls-sheet have three domains: example1.net, example2.com, example3.org. The inbox contains emails from a lot of different domains but I want only filter on these three domains in the xls.
Should I read the excel and create a loop that creates a string to be saved in a variable? Then use the variable in the filter?: “[ReceivedTime]>=’ “+ Now.AddDays(-1).ToString(“yyyy-MM-dd HH:mm”) +”'” AND vVariableWithDomains
Dont know the syntax but something like this within the variable:
vVariableWithDomains = “[From]= *@example1.net OR [From]= *@example2.com OR [From]= *@example3.org”
I believe after you use an activity to read in your MailMessages you can use a filter method with .Where (which is what I use).
Let’s assume your MailMessages variable is maillist
maillist.Headers will give you a list contained in the email and I think maillist.Headers(0) or maillist.Headers(“Date”) will give you the date.
Here is an example for one sender (also works if you use a For each sender):
maillist.Where(Function(m) m.From.ToString.ToUpper.Contains("SENDER") and CDate(m.Headers("Date").ToString)>=Now.AddDays(-1) ).ToArray
So for multiple senders you can either add in additional conditions with OR
or you can use a list of senders:
In this case, let’s assume dt is the datatable containing the senders and we can use some vb.net…
maillist.Where(Function(m) Array.IndexOf(dt.AsEnumerable.Select(Function(r) r(0).ToString.Trim.ToUpper).ToArray,m.From.ToString.ToUpper) > -1 and CDate(m.Headers("Date").ToString)>=Now.AddDays(-1) ).ToArray
So in the above it checks if the From has an index over 0 from the Array of senders in column A.
Now, you can process for the filtered list of mailmessages.
I apologize if there are some errors cause I did not test these examples in this post.
Try something like this in filter. This worked for me in the past for outlook 2010, bad news is for senderemailaddress I always got 0 rows. You can play around if you want.
"@SQL= urn:schemas:httpmail:sendername like '%xyz%'"
I have a bit similar topic:
I try to filter mails in the inbox by using the subject of the mails and the activity “IF” and the “variable 1” which is a date with format MM/DD/YYYY 00:00
if: mail.Subject.contains(Variable1)
Then : Message box:yes
Else: Message box: No
The result is anomaly always “No” even if when it should be “Yes”