Blog Post

Azure Integration Services Blog
6 MIN READ

Protect embedded image in email body while processing the mails in Logic Apps

Joyce_Dorothy's avatar
Joyce_Dorothy
Icon for Microsoft rankMicrosoft
Nov 24, 2022

If there are any inline image/signature logo in the email body, then the 'When a new email arrives (V3)' Office 365 Outlook trigger, will consider the inline image as attachments and for all the inline attachments we will have the Inline property is set to true in the trigger output.

In the below input email, I have included an image and Microsoft logo in the signature.

 

 

 

 

Please find the below logic App Trigger output for the above mail,          

 

We see there are two attachment objects in the trigger output which implies both the inline images (including logo in the signature) is considered as attachment. Note: All the inline images will have the inline property set to ‘true’ and also the name for the inline images starts with ‘image00’.

 

If you see the body content below (highlighted in yellow), the src field specifies which attachment needs to be referred to get the content.

 

cid:image001.png@01D8FE96.7BAE9C60

cid:image002.jpg@01D8FE96.7BAE9C60

 

The above CID value refers to the content ID field of the attachments (refer Screenshot 2) 

 

Trigger Body Output:

 

"body": {

        "id": "AAMkADFmYjI3YjgyLTdlZGEtNDIyYS04YTc2LTdkMjQ1ZmU2N2RhMwBGAAAAAADtpf10eIB1Sp-3Eu4NJu7dBwBIiBo_CW2YRoorZ7738DQsAAAAAAEMAABIiBo_CW2YRoorZ7738DQsAAMxDatgAAA=",

        "receivedDateTime": "2022-11-22T11:49:04+00:00",

        "hasAttachments": false,

        "internetMessageId": "TYZP153MB073818E4042752590B9E44C2E60D9@TYZP153MB0738.APCP153.PROD.OUTLOOK.COM",

        "subject": "Testdata",       

   "bodyPreview""Hello Everyone,\r\n\r\n\r\n\r\nThanks,\r\nJoyce Dorothy S",

        "importance": "normal",

        "conversationId": "AAQkADFmYjI3YjgyLTdlZGEtNDIyYS04YTc2LTdkMjQ1ZmU2N2RhMwAQAPrBywiOS3BLjCccIIGXmVM=",

        "isRead": false,

        "isHtml": true,

        "body": "<html><head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><meta name=\"Generator\" content=\"Microsoft Word 15 (filtered medium)\"><style>\r\n<!--\r\n@font-face\r\n\t{font-family:\"Cambria Math\"}\r\n@font-face\r\n\t{font-family:Calibri}\r\np.MsoNormal, li.MsoNormal, div.MsoNormal\r\n\t{margin:0cm;\r\n\tfont-size:11.0pt;\r\n\tfont-family:\"Calibri\",sans-serif}\r\na:link, span.MsoHyperlink\r\n\t{color:#0563C1;\r\n\ttext-decoration:underline}\r\n.MsoChpDefault\r\n\t{font-size:10.0pt}\r\n@page WordSection1\r\n\t{margin:72.0pt 72.0pt 72.0pt 72.0pt}\r\ndiv.WordSection1\r\n\t{}\r\n-->\r\n</style></head><body lang=\"EN-IN\" link=\"#0563C1\" vlink=\"purple\" style=\"word-wrap:break-word\"><div class=\"WordSection1\"><div><div><p class=\"MsoNormal\">Hello Everyone,</p><p class=\"MsoNormal\">&nbsp;</p><p class=\"MsoNormal\"><span lang=\"EN-GB\" style=\"\"><img width=\"250\" height=\"203\" id=\"Picture_x0020_1\" src=\cid:image001.png@01D8FE96.7BAE9C60\ style=\"width:2.6041in; height:2.118in\"></span></p><p class=\"MsoNormal\">&nbsp;</p><p class=\"MsoNormal\">&nbsp;</p><table class=\"MsoNormalTable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse:collapse\"><tbody><tr style=\"height:36.7pt\"><td width=\"252\" valign=\"top\" style=\"width:189.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:36.7pt\"><p class=\"MsoNormal\" style=\"line-height:12.0pt\"><b><span style=\"font-size:12.0pt\">Joyce Dorothy S</span></b></p></td><td width=\"540\" valign=\"top\" style=\"width:405.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:36.7pt\"><p class=\"MsoNormal\" style=\"line-height:12.0pt\"><span style=\"font-size:10.0pt; color:gray\">&nbsp;</span></p></td><td width=\"16\" colspan=\"2\" valign=\"top\" style=\"width:11.8pt; padding:0cm 5.4pt 0cm 5.4pt; height:36.7pt\"><p class=\"MsoNormal\" align=\"right\" style=\"text-align:right; line-height:12.0pt\"><span style=\"font-size:9.0pt; color:#505050\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p></td></tr><tr style=\"height:2.5pt\"><td width=\"800\" colspan=\"3\" valign=\"top\" style=\"width:600.1pt; padding:0cm 5.4pt 0cm 5.4pt; height:2.5pt\"><p class=\"MsoNormal\"><span style=\"font-size:8.0pt\">&nbsp;</span></p></td><td width=\"8\" style=\"width:6.0pt; padding:0cm 0cm 0cm 0cm; height:2.5pt\"><p class=\"MsoNormal\">&nbsp;</p></td></tr><tr><td width=\"186\" style=\"width:139.5pt; padding:0cm 0cm 0cm 0cm\"></td><td width=\"340\" style=\"width:255.0pt; padding:0cm 0cm 0cm 0cm\"></td><td width=\"14\" style=\"width:10.5pt; padding:0cm 0cm 0cm 0cm\"></td><td width=\"14\" style=\"width:10.5pt; padding:0cm 0cm 0cm 0cm\"></td></tr></tbody></table><p class=\"MsoNormal\"><span lang=\"EN-US\" style=\"color:black\">&nbsp;&nbsp; </span><span lang=\"EN-GB\" style=\"\"><img border=\"0\" width=\"137\" height=\"29\" id=\"Picture_x0020_2\" src=\cid:image002.jpg@01D8FE96.7BAE9C60\ style=\"width:1.4305in; height:.3055in\"></span></p></div></div></div></body></html>",

        "from":xxxxxxx@microsoft.com,

        "toRecipients":xxxxxxx@microsoft.com,

        "ccRecipients": null,

        "bccRecipients": null,

        "replyTo": null,

        "attachments": [

            {

                "@odata.type": "#microsoft.graph.fileAttachment",

                "id": "AAMkADFmYjI3YjgyLTdlZGEtNDIyYS04YTc2LTdkMjQ1ZmU2N2RhMwBGAAAAAADtpf10eIB1Sp-3Eu4NJu7dBwBIiBo_CW2YRoorZ7738DQsAAAAAAEMAABIiBo_CW2YRoorZ7738DQsAAMxDatgAAABEgAQAHoH6z66yT5Ctx_ClMH6LJ0=",

                "lastModifiedDateTime": "2022-11-22T11:49:04+00:00",

                "name": "image001.png",

                "contentType": "image/png",

                "size": 192413,

                "isInline": true,

                "contentBytes": null

            },

            {

                "@odata.type": "#microsoft.graph.fileAttachment",

                "id": "AAMkADFmYjI3YjgyLTdlZGEtNDIyYS04YTc2LTdkMjQ1ZmU2N2RhMwBGAAAAAADtpf10eIB1Sp-3Eu4NJu7dBwBIiBo_CW2YRoorZ7738DQsAAAAAAEMAABIiBo_CW2YRoorZ7738DQsAAMxDatgAAABEgAQAISicLX_8dJCiWWp-rgxU2g=",

                "lastModifiedDateTime": "2022-11-22T11:49:04+00:00",

                "name": "image002.jpg",

                "contentType": "image/jpeg",

                "size": 1893,

                "isInline": true,

                "contentBytes": null

            }

        ]

    }

 

Screenshot 2:

 

 

Inorder to display inline image, the base64 content must be included in the html text.

 

The below cid values (cid :<content id> in the trigger body output needs to be replaced with data:<contentType>;base64 {ContentBytes}:

cid:image001.png@01D8FE96.7BAE9C60

cid:image002.jpg@01D8FE96.7BAE9C60`

 

In the logic app, we need to implement the logic to replace the src=cid:<content id> (note: This content id is retrieved from the Get Attachment action with src=data:{contenttype};base64 {content Bytes}  and these values  {contenttype} and {content Bytes} are also retrieved from the Get Attachment action.

 

Logic App Implementation:

In the Mail Body variable, you need to assign the email body and then in the condition you can check if the inline property is true and if the name starts with ‘image00’

 

 

 

 

In the variable, you can use the replace function to replace src=cid:<content id> with src=data:{contenttype};base64 {content Bytes} 

replace(variables('varbody'),concat('cid:',body('Get_Attachment_(V2)')?['contentId']),concat('data:',body('Get_Attachment_(V2)')?['contentType'],';base64,',body('Get_Attachment_(V2)')?['contentBytes']))

 

 

 

 

 

Updated Nov 24, 2022
Version 2.0
No CommentsBe the first to comment