[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

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

Posted on 2008-02-05
2
Medium Priority
?
2,246 Views
Last Modified: 2010-04-21
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.



   
0
Comment
Question by:whorsfall
2 Comments
 
LVL 5

Accepted Solution

by:
Colemss earned 2000 total points
ID: 20827940
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
 
LVL 1

Author Closing Comment

by:whorsfall
ID: 31428146
Excellent !!! Ok another 500 points to take that example a bit further. Look at the next question.. :)
0

Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question