Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Following is the code which sends single embedded image very fine from Outlook using c#

C#
public void sendEMailThroughOUTLOOK()
    {
        try
        {
           Outlook.Application oApp = new Outlook.Application();

            Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

            string imageCid = "image001.jpg@123";
            oMsg.HTMLBody = String.Format("<body><img src=\"cid:{0}\"></body>", imageCid);
            Attachment attachment1 = oMsg.Attachments.Add(@"E:\wallpapers\WRLDMAP.jpg", OlAttachmentType.olEmbeddeditem, null, "img");
            attachment1.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid);

                           //Add an attachment.
            String sDisplayName = "MyAttachment";
            int iPosition = (int)oMsg.HTMLBody.Length + 1;
            int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
            //now attached the file

            Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\SampleFile.txt", iAttachType, iPosition, sDisplayName);

            //Subject line
            oMsg.Subject = "Your Subject will go here.";
            // Add a recipient.
            Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
            Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("abc8@in.com");
            oRecip.Resolve();

            oMsg.Send();
            oRecip = null;
            oRecips = null;
            oMsg = null;
            oApp = null;
        }
        catch (System.Exception ex)
        {   }
}


I dont know how to send multiple embedded images. What modifications are required in the above code?
Posted

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