Sending email using Microsoft.Office.Interop.Outlook; with image attatchment

Viewed 52

I am trying to send an email with an image attachment using Microsoft.Office.Interop.Outlook.

Here is my code:

Application OutlookApplication = new Application();
MailItem email = (MailItem)OutlookApplication.CreateItem(OlItemType.olMailItem);

email.Subject = Title;
email.To = ToUserName + "@gmail.com";
email.Importance = StringPriortyToOLImportance(SelectedPriority);

Attachment attachment = email.Attachments.Add(
    @imagePath
    , OlAttachmentType.olEmbeddeditem
    , null
    , "Screenshot"
    );

string imageCid = Path.GetFileName(imagePath);

attachment.PropertyAccessor.SetProperty(
  "http://schemas.microsoft.com/mapi/proptag/0x3712001E"
  , imageCid
  );

imagesHTML = "<img src=\"cid:" + imageCid + "\">";

email.HTMLBody = "<body>" + Description + "<br><br>" + imagesHTML + "</body>";

email.Send();

The code does send emails, the only issue I am having is the images appear like so: ImageError and I can't seem to find a solution to this.

Any help is greatly appreciated.

0 Answers
Related