Home > DeveloperSection > Forums > How to fetch Outlook email body using C#?
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    November-14-2013 3:15 AM

 C# C# 
Ratings:


 1 Reply(s)
 2897  View(s)
Rate this:

I am trying to make a function that fetches the body of an email with a given search criteria. When I fetch items from the mailbox and try to get the body, it only writes part of the body. I want ALL text from the body instead. How can I do this? This is what I have so far:

Outlook.Application myApp = new Outlook.Application();

        const string PR_HAS_ATTACH = "http://schemas.microsoft.com/mapi/proptag/0x0E1B000B";

        // Obtain Inbox

        Outlook.Folder folder = myApp.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox) as Microsoft.Office.Interop.Outlook.Folder;

        Outlook.Table table = folder.GetTable(Microsoft.Office.Interop.Outlook.OlTableContents.olUserItems);

        // Remove default columns

        table.Columns.RemoveAll();

        // Add using built-in name

        table.Columns.Add("Subject");

        table.Columns.Add("ReceivedTime");

        table.Sort("ReceivedTime", Microsoft.Office.Interop.Outlook.OlSortOrder.olDescending);

        // Add using namespace

        // Date received

        table.Columns.Add("urn:schemas:httpmail:textdescription");

        while (!table.EndOfTable)

        {

            Outlook.Row row = table.GetNextRow();

            if (row["Subject"].ToString().ToLower().Contains(subject.Text.ToLower()) && row["ReceivedTime"].ToString().Contains(cellCreationDate))

            {                   

                body.Text = row["urn:schemas:httpmail:textdescription"].ToString();

            }

        }



ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    November-14-2013 4:53 AM

Hi Jay,

Here is an alternative.

// change this in your code

body.Text = row["urn:schemas:httpmail:textdescription"].ToString();

// To this

Microsoft.Office.Interop.Outlook.MailItem mailItem =

                             myApp.Session.GetItemFromID(row["EntryID"]);

body.Text = mailItem.Body;


Don't want to miss updates? Please click the below button!

Follow MindStick