Search code examples
javaoutlookoracle-adfjdeveloperrich-text-editor

Sending embedded image in adf rich text editor to outlook is not working


I'm using Jdeveloper 11g R2 and I have this case.

i HAVE A .jspx page where clients will be able to send emails through it. in the body I am using ADF Rich Text Editor. In this ADF rich text editor the user will be able to insert in it images and text. the image needs to be inside the editor and not Attachment. usually this image will be a screen shot were the user will press the PrtScn button and then past the screen shot inside the editor. If I go to the source code i will find the source code of the image will look like this

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABaAAAAOECAYA.........>

Also I am using Java outlook connector in order to be able to send the email to outlook. I bound the Editor to my bean and below is how I'm sending it:

 `Outlook outlookApplication = new Outlook();
OutlookFolder outbox = outlookApplication.getDefaultFolder(FolderType.OUTBOX);
OutlookMail mail = (OutlookMail) outbox.createItem(ItemType.MAIL);
mail.setSubject("Hello HELLO!!!");
mail.setTo("User");
String edtrContent = geteditor().getValue().toString();
mail.setHTMLBody("<HTML><Body>" + edtrContent + "</Body></HTML>");
mail.send

The email is sent successfully to my outlook mail and I can only read the text sent. On the other hand I am not able to see the image that was sent in the rich text editor and it is appearing as a small box having X in red.


Solution

  • As Dmitry noticed, you need to add an embedded attachment to add images to the message body.

    1. Add the attachment using the Attachments.Add method.
    2. Set the PR_ATTACH_CONTENT_ID property using the PropertyAccessor object.
    3. Set the cid value (see #2) for the reference in the message body.

            string img = "<br/><p><o:p><img src=\"" + att.FileName
               + "\" width=1 height=1 border=0 /></o:p></p>";
            item.HTMLBody = item.HTMLBody.Replace("</body>", img + "</body>");
            string PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x3712001E";
            string HIDDEN_ATTACHMENT = "http://schemas.microsoft.com/mapi/proptag/0x7FFE000B";
            var pa = att.PropertyAccessor;
            if (pa != null)
            {
               pa.SetProperty(PR_ATTACH_CONTENT_ID, att.FileName);
               pa.SetProperty(HIDDEN_ATTACHMENT, false);
            }