Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First add a reference to Microsoft.Office.Interop.Outlook, then add these using statements</p> <pre><code>using Microsoft.Office.Interop.Outlook; using _Application = Microsoft.Office.Interop.Outlook._Application; using Outlook = Microsoft.Office.Interop.Outlook; </code></pre> <p>Then add this</p> <pre><code>//declare Outlook application _Application objOutlook = new Outlook.Application(); //create it _NameSpace objNs = objOutlook.Session; //create new session MAPIFolder oPublicFolders = objNs.Folders["Public Folders"]; MAPIFolder oAllPublicFolders = oPublicFolders.Folders["All Public Folders"]; Items itms = oAllPublicFolders.Items; foreach (MailItem item in itms) { GetNewMailItem(objOutlook, objContacts, item); } Marshal.ReleaseComObject(objOutlook); //release outlook com object </code></pre> <p>This next piece is just what I did, please change all of this code to fit your needs.</p> <pre><code>private static void GetNewMailItem(_Application objOutlook, MAPIFolder objContacts, MailItem item) { if(item.ReceivedTime.Date == DateTime.Now.Date.AddDays(-1) || item.UnRead) { if (item.Attachments.Count &gt; 0) { var attachments = item.Attachments; foreach (Attachment attachment in attachments) { if(attachment.Type == OlAttachmentType.olEmbeddeditem) { ProcessEmbeddedEmailAttachment(attachment, objOutlook, objContacts); } else if (attachment.FileName.EndsWith(".doc") || attachment.FileName.EndsWith(".docx")) { ExtractAttachment(attachment); item.UnRead = false; } } } } } </code></pre> <p>I am leaving out the rest of the code because it was specific to my processing.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload