Note that there are some explanatory texts on larger screens.

plurals
  1. POEnumerating Outlook Mailbox using Visual Studio
    primarykey
    data
    text
    <p>I have the following class which is intended to return the subject line of all the emails in a folder</p> <p>It is Visual Studio 2008 against Outlook 2007 running on Windows 7 64bit</p> <pre><code>using System; using System.Windows; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office.Interop.Outlook; namespace MarketingEmails { public class MailUtils { public static string[] processMailMessages(object outlookFolder) // Given an Outlook folder as an object reference, return // a list of all the email subjects in that folder { // Set a local object from the folder passed in Folder theMailFolder = (Folder)outlookFolder; string[] listSubjects = new string[theMailFolder.Items.Count]; int itemCount = 0; // Now process the MAIL items foreach (MailItem oItem in theMailFolder.Items) { listSubjects[itemCount] = oItem.Subject.ToString(); itemCount++; } return listSubjects; } } </code></pre> <p>}</p> <p>However the code throws the exception below:</p> <p>Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MailItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).</p> <p>I understand that the error which has occurred because it is trying to process a ReportItem in the selected mailbox. </p> <p>What I don't understand is <strong>why</strong> is it trying ro process non-Mail Items when I have specified:</p> <pre><code>foreach (MailItem oItem in theMailFolder.Items) </code></pre> <p>If I wanted it to process Report Item entries in the mailbox I would have written: </p> <pre><code>foreach (ReportItem oItem in theMailFolder.Items) </code></pre> <p>I would dearly like to find out if this is a bug or if it is just my mis-understanding</p> <p>Regards, Nigel Ainscoe</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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