none
How to add images to a dynamically created Outlook signature(html) ? (cid and base64 encoded not working) RRS feed

  • Question

  • Hi,

    I have created an Outlook(for outlook 2016) Add-in that gives the users the possibility to compose theire own signature based on company rules.

    Within that (hmtl)signature there are social media icons (images).

    I have used base64 encoded images but that doesn't seem to work, the image encoded string is cutt off when the signature is set.

    I have also used file:/// and location of images , hoping it would be translated by outlook into cid but that also did not work.

    Placing the images on a network share is not an option.

    Has someone a solutions?

    Thanks

    Kind Regards



    Mas Unit

    Tuesday, July 4, 2017 8:49 AM

Answers

  • Thanks for the reply but my Add-in works differently.

    My add-in doesn't create a mail it changes/creates signatures and sets them as outlooks default.

    So there is no mailItem in my flow.

    But I found a solution to my problem.

    For outlook 2016 to import my images as cid I have to add them to a filelist.xml file that is located in the outlook signatures folder.

    I also needed to adapt my signature html file to import a lot of meta tags that oultook uses once you create a new mail.

    Again thanks for the reply.

    I haven't found this way of changing/creating signatures throughout the web or on any forum.


    Mas Unit

    • Proposed as answer by Chenchen LiModerator Wednesday, July 5, 2017 9:17 AM
    • Marked as answer by M in M Thursday, July 6, 2017 6:40 AM
    Wednesday, July 5, 2017 8:02 AM

All replies

  • Hello,

    How do you create the signature and then insert to the mail body?

    I create the mail item and test the mailbody using the code below. The base64string doesnt work for me too. And i try to add a breakpoint to check the HTML string and the image is fine when showing in HTML format in VS.

    After adding an image manually in Outlook and checking its htmlbody. The html shows Outlook uses cid for the image, so please simiply pass the path of the image. For my test result, mail.HTMLBody = @"<img src="""+path+@""">"; could successfully insert the image. If it doesnt work for you, please share detail information like how you create the signature and then insert.

                Outlook.MailItem mail=
                Globals.ThisAddIn.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                string path = @"E:\1.jpg";
                //mail.HTMLBody = @"<img src="""+path+@""">";
                mail.HTMLBody = @"<img src=""data: image / png; base64," + Imagebase64(path) + @""">";
                mail.Display();
    
    
           string Imagebase64(string path)
            {
                using (Image image = Image.FromFile(path))
                {
                    
                    using (MemoryStream m = new MemoryStream())
                    {
                        image.Save(m, image.RawFormat);
                        byte[] imageBytes = m.ToArray();
                       
                        // Convert byte[] to Base64 String
                        string base64String = Convert.ToBase64String(imageBytes);
                        return base64String;
                    }
                }
            }

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 5, 2017 6:04 AM
    Moderator
  • Thanks for the reply but my Add-in works differently.

    My add-in doesn't create a mail it changes/creates signatures and sets them as outlooks default.

    So there is no mailItem in my flow.

    But I found a solution to my problem.

    For outlook 2016 to import my images as cid I have to add them to a filelist.xml file that is located in the outlook signatures folder.

    I also needed to adapt my signature html file to import a lot of meta tags that oultook uses once you create a new mail.

    Again thanks for the reply.

    I haven't found this way of changing/creating signatures throughout the web or on any forum.


    Mas Unit

    • Proposed as answer by Chenchen LiModerator Wednesday, July 5, 2017 9:17 AM
    • Marked as answer by M in M Thursday, July 6, 2017 6:40 AM
    Wednesday, July 5, 2017 8:02 AM
  • Hello,

    Thanks for sharing the solution here, i think it would be of great help for others. I suggest you mark it as answer to close this thread and people with similar issue could find the useful information here.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 5, 2017 9:17 AM
    Moderator