We are trying to send emails that have a body filled up by users. They are able to add an image in the body, which is displayed in a rich text box.
but the new control for rich text boxes is putting links to content inside Pega so, once it is send it is still content to Pega and therefore not displayed on client mail software of recipients.
After long researches on internet and mesh, it seems images in emails should be put in attachments and referenced by a cid:UniqueID in the src of the img content inside the html of the body. Or it is possible to encode in base64 the content of the image and put it in the email, no my preferred solution
It seems it is what Pega is doing since 7.1.8 on email received but there is nothing to send email like this.
We are in a special case where we use Exchange webService to connect to an exchange server to receive and send emails. So we also have an issue in received emails to handle the images.
Has anyone already faced this issue, and may be found a solution ?
I have no difficulty to handle the EWS api so I know how to get or set attachments, including how to flag them as inline attachments, the issues are how to deal in pega for :
Display links to images that are stored as Data-WorkAttach-File objects for inbound emails (little issue will be to parse the bode to look for all img content but that should not be a big deal)
Download content added by users to move them to attachments with a unique Id.
For sending images, we don't want to send only the link, we want the image to be inside the email, as an attachement. Our server is not reachable from outside the company and emails are supposed to be send to anyone so links is not something possible. Also we do not control the mail client software that will read the messages so we don't know if external images are blocked.
For inbound messages yes I saw this option but as we don't use email listener, we can't just check this option. Also, we would like not to put the entire image in the email body, which will have a performance impact but rather create links to an attachment.
If you look at how works the rich text box for images, you will see that importing images put them into a specific folder and in the rich text box there is a link to this folder. We want to be able to create such links for every incoming emails but pointing to attachments of this email that will be hidden to the user.
When you uplaod an image with the rich text editor, it creates a link to "../datacontent/image/rteimages/ImageFileName.ImageExtension". We don't have fully qualified image url from outside our Pega server., images are from user computer.
I managed to send emails with images and retrieve them following this algorithm:
- Retrieve emails :
- Search on body using regex "<img.+src=\"cid:+\".+>" all images inline.
- For each found image content id, open the attachment with same id and create an instance of data-content-image
- Create link to new instance of Data-Content-image like "../datacontent/image/rteimages/ImageFileName.ImageExtension" and put it in src attribute instead of cid:...
For security on these images, I added some properties on Data-WorkAttach-File where I store the attachments of emails to set the pzInsKey of the Data-Content-File which allow to use the links of the attachments on WO to add security on access-role-obj to the Data-Content-Image class
- Send emails:
- Search on body using regex "<img.+src=\".+\".+>" (I check later if src starts with ..\datacontent/image/rteimages, could do in regex)
- Parse src to get image filename and extension
- Open the data-content-image instance created automatically by rich text editor
- Create Data-WorkAttach-file instance and copy data from data-content-image and create a content id on this Data-WorkAttach-File
- replace link in mail to cid:ContentId of workAttach-file
- add the Workattach-File created as attachment of the email (don't forget to set it as inline type of attachment)
Those algorithm doesn't contain some optimizations I've done to improve performances and number of instances created in case of reply to send emails containing images and so on.