VSTO Outlook Embed Image MailItem

感情迁移 提交于 2019-11-28 08:49:43
Esteban Lopez

Finally i Solved the problem with this:

private void SendFormatted(Outlook.MailItem mail)
{
    if (!string.IsNullOrEmpty(mail.HTMLBody) && mail.HTMLBody.ToLower().Contains("</body>"))
    {
        //Get Image + Link
        string imagePath = @"D:\\Media\Imagenes\100MSDCF\DSC00632.JPG";
        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, Outlook.OlAttachmentType.olByValue, mail.Body.Length, 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();
    }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!