HOW TO FETCH OUTLOOK EMAIL BODY USING C#?

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
C# 
C#
 4323  View(s)
Ratings:
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();

            }

        }

  1. ezra heywood

    Post:145

    Points:1019
    Re: How to fetch Outlook email body using C#?

    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;

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!