Extreme novice with C# here. I'm attempting to get a count for the number of emails that have a subject line that begins with "RE:" that were sent to me within the last month. For example something like below but instead of restricting to emails that only have "RE:" as the subject, I'd like to restrict only to emails that have a subject line beginning with "RE:" and that have a sent date within the last month. Any help would be much much appreciated. Thank you!
Outlook.Items repliedItems = inbox.Items.Restrict(@"[Subject] = ""RE:""");
You can use DASL queries with the ci_startswith
or ci_phrasematch
operators. For example, the following query performs a phrase match query for RE:
in the message subject:
filter = "@SQL=\"http://schemas.microsoft.com/mapi/proptag/0x0037001E\" ci_phrasematch 'RE:'"
Also you'd need to combine another search criteria to the string passed to the Restrict
method - items were sent to me within the last month. Use the MailItem.ReceivedTime property which returns a date indicating the date and time at which the item was received. The following articles explains how to use DateTime structures for filtering items in Outlook: