Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys.

I am creating a VSTO for outlook 2007.

What I am doing is I added a bunch of images to my resources folder of my application, I then loop through the folder and then get the images in the folder and for each image in that folder create a button and set that buttons background to the image.

I have a ribbon on the new email window, and when that is clicked a form with the above buttons with its background images comes up. What i want to happen now is on the buttons click event i need to insert the button that was clicked's background image to the new email.

I need the method to embed the image using the image object from the buttons background image and not using a string referencing an image from my hard disk.

Please advise on what to do, any help will be much appreciated.

Thanks in advance guys.

Here is my code for embedding the image in the email:


XML
public void AddImage(MailItem mail, Image image)
{
if (!string.IsNullOrEmpty(mail.HTMLBody) && mail.HTMLBody.ToLower().Contains("</body>"))
            {
                int mailBodyLength;
                if (mail.Body == null)
                {
                    mailBodyLength = 0;
                }
                else
                {
                    mailBodyLength = mail.Body.Length;
                }
                //Get Image + Link
                Image imagePath = image;
                object linkAddress = "http://www.pentavida.cl";

                //CONTENT-ID
                const string SchemaPR_ATTACH_CONTENT_ID = @"http://schemas.microsoft.com/mapi/proptag/0x3712001E";
                string contentID = Guid.NewGuid().ToString();

                //Attach image
                mail.Attachments.Add(imagePath, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, mailBodyLength, Type.Missing);
                mail.Attachments[mail.Attachments.Count].PropertyAccessor.SetProperties(SchemaPR_ATTACH_CONTENT_ID, contentID);

                //Create and add banner
                string banner = string.Format(@"<br/><a href=""{0}"" ><img src=""cid:{1}"" ></a></body>", linkAddress, contentID);
                mail.HTMLBody = mail.HTMLBody.Replace("</body>", banner);

                mail.Save();
            }
}


But using this method throws an exception at this line:
mail.Attachments.Add(imagePath, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, mailBodyLength, Type.Missing);

the exception that gets thrown is :
Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
Posted
Updated 7-Feb-12 21:56pm
v2
Comments
bbirajdar 7-Feb-12 9:25am    
Please post your code so that we can save time in guessing what exactly you want to achieve.
Member 8102934 8-Feb-12 3:57am    
I have edited my question to add my code.
Member 8102934 8-Feb-12 3:57am    
I have edited my question to add my code.

1 solution

You need to use the LinkedResource class in .NET

Check the complete implementation here

http://www.dotnetobject.com/Thread-How-to-embed-a-image-in-a-email[^]

Do not forget to vote my solution.
 
Share this answer
 
Comments
Member 8102934 7-Feb-12 6:54am    
Thanks for the response, but that is not what i am looking for. This part over here passes a path of the image: LinkedResource LinkedImage = new LinkedResource(@"J:\My Documents\Advika1.jpg"); I need to pass the image object to accomplish what i need to do.

for example:

Image i = Resources.Jellyfish;
LinkedResource LinkedImage = new LinkedResource(i);
Member 8102934 8-Feb-12 3:57am    
I have edited my question to add my code.

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