Search outlook mail Element for displayed received date instead of header information Date in C #

I received the mail in June 25, 2013 14:52:37 -0400 (EDT) and it displays:

Wed 6/26/2013 12:29 AM  (in GMT).

Now in my application c # windows when I load the mail item

this mail is not displayed between the received date from June 26 to June 28 (if we classify it between the received date from June 25 to June 28) my search term is as follows:

"urn:schemas:httpmail:datereceived >= '6/26/2013' AND  "urn:schemas:httpmail:datereceived"" <='6/28/2013'

How to apply my search in the displayed date and time instead of the information in the header information?

+1
source share
1 answer

My answer is here

  using OutLook = Microsoft.Office.Interop.Outlook; 

    OutLook.Application outlookObj;
     OutLook.NameSpace olintNS; 
    OutLook.MailItem mailitem; 
    mailitem = outlookObj.CreateItem(OutLook.OlItemType.olMailItem);
     OutLook.PropertyAccessor pa = mailitem.PropertyAccessor; 

    DateTime datStartUTC = pa.LocalTimeToUTC(Convert.ToDateTime("6/26/2013"));
     DateTime datEndUTC =pa.LocalTimeToUTC(Convert.ToDateTime("6/28/2013").AddDays(1)); 

// Search Status

     string filter = @"@SQL=((""urn:schemas:httpmail:datereceived"" >= '" + datStartUTC + @"' AND ""urn:schemas:httpmail:datereceived"" <='" + datEndUTC + @"' ) OR (""urn:schemas:httpmail:date"" >= '" + datStartUTC + @"' AND ""urn:schemas:httpmail:date"" <='" + datEndUTC + @"' ) ) ";
 OutLook.Items items = oFolder.Items.Restrict(filter);

 // Now I can Put searched item in to My DataTable

foreach (OutLook.MailItem mail in items) 
{ 
DataRow dr = dtInbox.NewRow(); 
dr["TO"] = mail.To; 
dr["From"] = mail.SenderEmailAddress;
dr["Subject"] = mail.Subject;
dr["EntryID"] = mail.EntryID; 
dr["folderStoreID"] = oFolder.StoreID; dr["Date"] = mail.ReceivedTime;//? (mail.SentOn != null ? mail.SentOn.ToString("MM/dd/yyyy") : "") : (mail.ReceivedTime); dtInbox.Rows.Add(dr);
 }

+2
source

Source: https://habr.com/ru/post/1692261/


All Articles