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:
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))