Apisero is now part of NTT DATA - Learn more.

Search
Close this search box.

Setup BCC And CC Dynamically & Send Any File Using Outlook

Author: Atul Sharma

Prerequisites:- 

This blog contains steps on how we can send any files using the Outlook Connector. This method would work for sending all the files Using the Outlook Send Mail Connector.

Real time Scenario:- 

To send files of any type over email using the Outlook Email Application Service and dynamically setup the BCC and CC that would be triggered via the events from the Client’s end we can use the below setup to achieve the same.

Setup for Email Payload to Send any files:-
  1. In this use case we have sent all the attributes that needed to be used for sending the email that was in the form-data format.
  1. We stored all these attributes of the form-data body in a variable so that it can be easily manipulated and transformed the payload for the email connector.

Code:-

%dw 2.0
output application/java  
---
{
    "tenant_id": payload.parts.tenant_id.content,
    "to": payload.parts.to.content,
    "from": payload.parts.from.content,
    "attachment": payload.parts.*attachment,
    "body": payload.parts.body.content,
    "subject": payload.parts.subject.content,
    "cc": payload.parts.cc.content,
    "bcc": payload.parts.bcc.content,
}

The originalPayload depicted in the image will hold the payload for the variable.

**Note: The output of the above mentioned payload should be as application/java. Because if we set it up as the application/json the attachment details will be lost.

  1. Setting up the email Payload can be configured as follows so that the attachments of any type can be sent over the email using the Outlook Email Connector.

Code:-

%dw 2.0
output application/json  skipNullOn = "everywhere"
import toBase64 from dw::core::Binaries
fun fileFormat(formats,content)=if(formats=="text/csv" or formats=="text/yaml" or formats=="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") toBase64(write(content,formats) as Binary) else toBase64(content as Binary)
fun bcc()=if(isEmpty(vars.originalPayload."bcc")) "bccRecipients":[] else "bccRecipients": (vars.originalPayload."bcc" splitBy (",")) map(item,index) ->
      {
        "emailAddress": {
          "address": item
        }
      }
fun cc()=if(isEmpty(vars.originalPayload."cc")) "ccRecipients":[] else "ccRecipients": (vars.originalPayload."cc" splitBy (",")) map(item,index) -> 
      {
        "emailAddress": {
          "address": item
        }
      }
fun attachment()=if(isEmpty(vars.originalPayload."attachment")) "attachments":[] else "attachments": vars.originalPayload."attachment" map(item,index) ->
      {
        "@odata.type": "#microsoft.graph.fileAttachment",
        "name": item.headers."Content-Disposition".filename,
        "contentType": item.headers."Content-Type",
        "contentBytes": fileFormat(item.headers."Content-Type",item."content")
      }
---
{
  "message": {
    "subject": vars.originalPayload."subject",
    "body": {
      "contentType": "Text",
      "content": vars.originalPayload."body"
    },
    "toRecipients":  (vars.originalPayload."to" splitBy (",")) map(item,index) -> 
      {
        "emailAddress": {
          "address": item
        }
      }
  }++ bcc() ++ cc() ++ attachment(),
   "saveToSentItems": "false"
}
Input Request:-

Here we are sending an image file as an attachment. Please refer the following POSTMAN Request for the same.

Input Payload:-
Transformed Payload:-
{
  "message": {
    "subject": "Testing Outlook",
    "body": {
      "contentType": "Text",
      "content": "testing the outlook operation"
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "***********"
        }
      }
    ],
    "bccRecipients": [
      {
        "emailAddress": {
          "address": "***********"
        }
      }
    ],
    "ccRecipients": [
    ],
    "attachments": [
      {
        "@odata.type": "#microsoft.graph.fileAttachment",
        "name": "Request_Header.png",
        "contentType": "image/png",
        "contentBytes": "iVBORw0KGgoAAAANSUhEUgAAA50AAAEoCAYAAADbtJWlAAAgAElEQVR4nOzde1yUVf7A8Y/AOIA6XhAEZVZQ8jaaSGiNm4ppeUk0XZfWSNcM2zQ3M3+Wy1rmpsRWZJrZRTJ"
      }
    ]
  },
  "saveToSentItems": "false"
}
Email Received Example:- 
Conclusion:-

Thus, for sending all kinds of files using the Outlook email connector and dynamically setting up the bcc and cc the above mentioned steps can be implemented.

**Note: The below mentioned file types are blocked by the following Gmail Email Services: 

.cpl, .jar, .lnk, .vbs, .mst, .chm, .apk, .bat, .vbe, .appxbundle, .sys, .wsh, .jse, .hta, .diagcfg, .lib, .vb, .dll, .dmg, .js, .ade, .diagpack, .jnlp, .sct, .vxd, .adp, .isp, .com, .cmd, .msi, .xll .exe, .ex, .pif, .wsc, .msix, .shb, .scr, .msp, .appx, .ex_, .msixbundle, .ps1, .ins, .vhd, .cab, .img, .mde, .diagcab, .msc, .wsf, .nsh, .iso

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.