Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In Outlook 2013 I want content of mail body in a new mail programmatically.
Below is my code for same:
C#
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
    Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
    Outlook.Application oApp = new Outlook.Application();
    Outlook.Explorer oExplorer = oApp.ActiveExplorer();
    Outlook.Selection oSelection = oExplorer.Selection;

    foreach (object item in oSelection)
    {
        Outlook.MailItem mi = (Outlook.MailItem)item;
        mailItem.HTMLBody = mi.HTMLBody;
    }
}

Everything works fine, but the image present in original mail is not displayed, instead it shows something like cid:image002.png.

Not sure what is the reason please help.

Also i want to give it to client, so i can't save mail content local.
Posted
Updated 20-Oct-15 20:23pm
v2

1 solution

You need to copy the attachments over as well. Based on the context of the code that you gave, this should work:

C#
...
foreach (object item in oSelection)
    {
        Outlook.MailItem mi = (Outlook.MailItem)item;
        mailItem.HTMLBody = mi.HTMLBody;
        if(mi.Attachments != null && mi.Attachmets.Count > 0)
        {
           foreach(var attach in mi.Attachments)
           {
               mailItem.Attachments.Add(attach);
           }
        }
    }


In Outlook the attachments are used as the image data source for "embedded" images.
 
Share this answer
 
v2
Comments
Digambar Malla 22-Oct-15 1:27am    
Hi, Tried this...but it is giving following error near Add():
COMException was unhandled by user code
Nathan Minier 23-Oct-15 7:05am    
Okay, we'll add a null check, which might well resolve it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900