I have the following code to embed images to Outlook MailItems
:
private void ReplaceImageIds()
{
foreach(var image in Image.GetImagesFromText(HTMLBody))
{
var imageTag = $"<img src \" cid:{image.Id.ToString()} \"/>";
var attachment = _mailItem.Attachments.Add(image.FilePath, OlAttachmentType.olEmbeddeditem, null, "");
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001F", "image/png");
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", image.Id.ToString());
HTMLBody = HTMLBody.Replace($"ImageId={image.Id.ToString()}", imageTag);
}
}
That works just fine. The images are shown when i receive the e-mail - but just there.
When i take a look at my sent-mails folder in outlook the images are just shown like this:
Does anyone have an idea why they are shown like this and can help me to fix that?
I'm confused about that because the images are shown when i receive the e-mail.
Mail is send like this:
public Boolean Send()
{
// Check if all properties are set.
Validate();
try
{
var oApp = new Application();
var oNS = oApp.GetNamespace("mapi");
oNS.Logon();
_mailItem = oApp.CreateItem(OlItemType.olMailItem) as MailItem;
// Set To, CC and BCC.
AddRecipients();
// Replace images.
ReplaceImageIds();
if (Body != null)
_mailItem.Body = Body;
if(HTMLBody != null)
_mailItem.HTMLBody = HTMLBody;
_mailItem.Subject = Subject;
// Set account to send.
SetSendingAccount(oApp);
// Add attachments.
AddAttachments();
_mailItem.Send();
oNS.Logoff();
return true;
}
catch (System.Exception ex)
{
Utils.LogException(ex, "Could not send email.");
throw new System.Exception("Could not send email.", ex);
}
}
Thanks in advance.