none
Open outlook with emed image in body by java script RRS feed

  • Question

  • Hello ,

    •     I write java script code to open out look which contains an embed image in the body .
    •     I test the code the outlook opened successfully  , but the image not appeared.

         

    •   The code is  :

               function OpenOutLook(subject, to, cc, bcc, body, from) {
                        var body = '<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAa0AAABZCAIAAAACQOzbAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAzPSURBVHhe7Z3bb1THHcd5qVSh/hF5SJ+qqi9t06aRwkP70EaNCg9p2qpSK5SItJUwiatASkgKiWJxF025hRoSk3gDKqh2IJRyMyyCkLYJhcoNtsGhKcF2HgjhZhyb/mbmN3Nm5sysd717sGG+H41WZy6/mTnr/X2Y40XytMsBTu3e4LL7lN2ha1GqHDYhjm9ubm7efJxrXF/a2ctVAAColZAHz5dLpLFS+byoGKepVo2SnCNMFZAfplqMFWUMT+4Nd8dkVUNv59KA86xWsuLSzuNUV1i+lKOYbApvPHwKQIrEPeh7KC84x4ICYbeaPBicwbTnPBjWoN0uT4daf9J86tqJtCrOeFGBCQFIj+Bzsesyy0exc5rX4w6Le1D1mLPhuAhR2Uc8g+nwRuiqHyhMGBjvDwMAJEHQgwLlMk1QcAp7YI0e9BbxJs4T9ZTpoAv7RMcnP3kw9JHj4EEAQNyDjD4aKkU5gvNOjQLuqdqD+UkqHg6dp1uLrD3uwVAcPAgAIAIeZDVpcdlSs6/VMPaWGxPyoBMV1J0bFSZoKktzXr+uRgXndkSHAQDuZip9T2LhCE5ADVnFEBpmVw3Kg9GFKihRuMpXXXbYkzXdLSrcI1TpjlIVcQUPApA4kedix1DW4c20yzYjOKqpHlaXO8wVo7w2U4YXquBBgbIdY+wmkCbbrLudLqlCxjEiPAhA4oz3+8E7DJgMAFAz8CAAIHXgQQBA6txlHgQAgJqBBwEAqQMPAgBSBx4EAKQOPAgASB14EACQOvAgACB1fA8OAQBAYuA8CABIHXgQAJA68C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bbju8vAQeBEXBHzdQAPwWgwYBDwIAUgceBACkDjwIAEgdeBAAkDrwIAAgdeBBAEDqwIMAgNSBBwEAqQMPAgBSBx4EAKQOPAgASB14EACQOvAgACB14EEAQOrAgwCA1IEHAQCpAw8CAFIHHgQApA48CABIHXgQAJA68CAAIHXgQQBA6sCDAIDUgQcBAKkDDwIAUgceBACkDjwIAEgdeBAAkDrwIAAgdeBBAEDqwIMAgNSBBwEAqQMPAgBSBx4EAKQOPAgASB14EACQOvAgACB14EEAQOrAgwCA1PE9OAQAAEkxNPR/PMJqfsxJ0z0AAAAASUVORK5CYII=" />';

                        var theApp = new ActiveXObject("Outlook.Application");
                        var theMailItem = theApp.CreateItem(0);
                        theMailItem.to = "myemail@hotmail.com";
                        theMailItem.Subject = "Tets";
                        theMailItem.HTMLBody = body;
                        theMailItem.display();
              }

    •   If I take the img tag  and put it in HTML (ex:default.aspx) and run the page , the image appear.

            How Can I solve it?


    ASk

    • Moved by Steve Fan Wednesday, January 29, 2014 1:55 AM coding related question
    Tuesday, January 28, 2014 11:26 AM

Answers

  • HTML is rendered in Outlook by Word, not IE. Word does not understand embedded images.

    What you need to do is referrer the image using the cid attribute (<img src="cid:xyz">), add the image attachment using Attachments.Add, then set the PR_ATTACH_CONTENT_ID (DASL name http://schemas.microsoft.com/mapi/proptag/0x3712001F) appropriately ("xyz" in the example above) using Attachment.PropertyAccessor.SetProperty.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, January 29, 2014 3:17 AM

All replies