locked
Creating a Outlook Message in HTML Format RRS feed

  • Question

  • Hi All,
    I am using Outlook 2007 object model inorder to create a Outlook Mail Item (Message). Here is the code snippet that I am using:
    Microsoft.Office.Interop.Outlook.Application oOutlookApplication = new Application();
    Microsoft.Office.Interop.Outlook.MailItem oMailItem = (Microsoft.Office.Interop.Outlook.MailItem)
    oOutlookApplication.CreateItem(OlItemType.olMailItem); oMailItem.BodyFormat = OlBodyFormat.olFormatHTML;
    oMailItem.Body="<html><head><title></title></head>" + "<body>"+Convert.ToString(sbBody)+"</body></html>";
    //sbBody is a string builder object that holds the table with data. oMailItem.Subject = Convert.ToString(oOutlookListItem["Title"]); oMailItem.SaveAs(@"D:\\TestMailItem.msg", OlSaveAsType.olMSG);

    This is perfectly creating the Outlook mail item that I want. But the problem is that when I try to open the created item, I can directly see the html as body......

    but the output must be a table. Not sure what is the issue....

    Could anyone guide me in the right direction if incase I am missing out some thing?....
    Thanks Sridhar
    Wednesday, November 11, 2009 11:23 AM

Answers

  • A very small mistake huh........

    oMailItem.Body="<html><head><title></title></head>" +
                                    "<body>"+Convert.ToString(sbBody)+"</body></html>";
    In the above statement I have changed oMailItem.Body with oMailItem.HTMLBody
    and it works.......


    Hope this will be hekpful to someone :)
    Thanks Sridhar
    • Marked as answer by SridharV Wednesday, November 11, 2009 1:00 PM
    Wednesday, November 11, 2009 1:00 PM