Iterate through and Outlook 2007 Inbox using C# and Office 2007 PIA

Hi,

For maximun points 500 I am looking for some following code that will do the following:

1. Compile with Visual C# 2008 Express.

2. Open an Inbox in Outlook 2007 and itereate through every item within that mailbox.

   e.g. Open Inbox.
        foreach .... and loop through every mail item.
        Close mailbox
        exit program.
       
   Be great it it could also iterate through sub folders as well but hopefully I can adapt it
   once i get the starting point.
   
3. Must use the Outlook 2007 PIA classes and not the depreciated ones.

   Welcome to the Outlook 2007 Primary Interop Assembly Reference
   http://msdn2.microsoft.com/en-us/library/bb652780.aspx

4. It does not need to do anything to each item, just say print the email address of each
   on the console, I am just looking for a skeleton code I can adapt.
   
Maximun points for a working sample I can just copy and paste into C# 2008 express.

Thanks,

Ward.



   
LVL 1
whorsfallAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ColemssCommented:
http://msdn2.microsoft.com/en-us/library/bb612664.aspx

private void DemoTableColumns()
{
    const string PR_HAS_ATTACH =
        "http://schemas.microsoft.com/mapi/proptag/0x0E1B000B";
    // Obtain Inbox
    Outlook.Folder folder =
        Application.Session.GetDefaultFolder(
        Outlook.OlDefaultFolders.olFolderInbox)
        as Outlook.Folder;
    // Create filter
    string filter = "@SQL=" + "\""
        + PR_HAS_ATTACH + "\"" + " = 1";
    Outlook.Table table =
        folder.GetTable(filter,
        Outlook.OlTableContents.olUserItems);
    // Remove default columns
    table.Columns.RemoveAll();
    // Add using built-in name
    table.Columns.Add("EntryID");
    table.Columns.Add("Subject");
    table.Columns.Add("ReceivedTime");
    table.Sort("ReceivedTime", Outlook.OlSortOrder.olDescending);
    // Add using namespace
    // Date received
    table.Columns.Add(
        "urn:schemas:httpmail:datereceived");
    while (!table.EndOfTable)
    {
        Outlook.Row nextRow = table.GetNextRow();
        StringBuilder sb = new StringBuilder();
        sb.AppendLine(nextRow["Subject"].ToString());
        // Reference column by name
        sb.AppendLine("Received (Local): "
            + nextRow["ReceivedTime"]);
        // Reference column by index
        sb.AppendLine("Received (UTC): " + nextRow[4]);
        sb.AppendLine();
        Debug.WriteLine(sb.ToString());
    }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
whorsfallAuthor Commented:
Excellent !!! Ok another 500 points to take that example a bit further. Look at the next question.. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.