1

I have received an outlook mail at 25 Jun 2013 14:52:37 -0400 (EDT) and it is displaying:

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

Now in my C# window application when i am seraching mail item

this mail is not displaying between received date 26 June to 28 June (if we are seraching it between received date 25 June to 28 June it is displaying ) my search condition in as follows:

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

How to apply my search on Displayed date and time instead of Information in Header information?

tshepang
  • 12,111
  • 21
  • 91
  • 136
user2064337
  • 31
  • 1
  • 4

1 Answers1

2

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)); 

// My Search Condition

     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);
 }

user2064337
  • 31
  • 1
  • 4