In the previous blog, we have showcased how to send email notification leveraging MS Email adapter. In this article, we’ll see how to send email notification along with attachments.

Use Case: Send an email along with attachment

To achieve this use case, a REST service will be exposed which will take a file as an input parameter along with below payload and send the file as an attachment in the email notification to the recipient sent in the payload

“Body”:”Hi, Sending an email with attachment”,
“Subject”:”Attachment Testing”

Let’s get started and see how to achieve the use case

Below are the high-level activities which need to perform  to achieve the use case

  • Configure MS Email adapter in Oracle Integration Cloud 
  • Create REST Service

Configure MS Email adapter in Oracle Integration Cloud

Follow the blog to see how to configure MS email adapter

While configuring the email adapter, we had provided offline_access as a scope. Since we are sending an email instead of reading email then scope must be changed. So in this case scope will be offline_access

Create REST Service

  • Create an Orchestration Integration with the option of Application event or  business object
  • Drop REST adapter on the Integration Canvas as Trigger point
  • Enter the values and Click Next button
    • Name of the end point: GetAttachments
    • Relative URI(must start with /): /sendEmail
    • Select HTTP verb: POST
    • Select Configure a request payload for this endpoint checkbox- This option allows us to assign payload in the next step
  • In the Next screen choose below option and select Next
    • Select Accept attachments from request checkbox
    • Select JSON Sample Radio button: This option allows us to take input in json format. Select inline link to give sample payload and enter below the payload
“Body”:”Hi, Sending an email with attachment”,
“Subject”:”Attachment Testing”
  • Click Done button on Next screen to complete the Wizard
  • Drop the MS email adapter just below the REST service adapter
  • Enter endpoint name and click Next button
  • Select Send a new message operation and click Next button
  • Click Done button on Next screen to complete the Wizard
  • Open the Mapper, expand Message object and map values in below attributes
Body -> Content
ToRecipients -> EmailAddress -> Address
As per the Microsoft Document, to send an attachment in an email an Attachments object is required in the API. When we open the ICS mapper we don’t see this Attachments object. So we have to manually add the Attachments object by exporting the integration. 
  • Save the integration and click on the Export button
  • Open the SendAttachments_REQUEST.wsdl file in 7-zip directly which will be in below path. Highlighted number might be different
  • Search complex element of type “messageResource.definitions.messageResource” and add below element
<xs:element name=”Attachments” minOccurs=”0″ maxOccurs=”unbounded”>
                                    <xs:extension base=”messageResource.definitions.attachments”>
                                                <xs:attribute name=”odata.type” />
  • Add below complex element in the WSDL file
<xs:complexType name=”messageResource.definitions.attachments”>
                        <xs:element name=”Name” type=”xs:string” />
        <xs:element name=”ContentBytes” type=”xs:string” />
  • Save the file and import the integration back in OIC
  • Open the mapper again and see in the Target mapper, Attachments object would be shown
  • Hard code the value “#Microsoft.OutlookServices.FileAttachment” of odata.type attribute
  • Map the Request attachmentproperties – partName to Attachments – Name
  • Open the ContentTypes attribute and drop the function encodeReferenceToBase64 on the attribute
  • Drop the attachments->attachment->attachmentReference in the  function  encodeReferenceToBase64 
  • Below would be the final mapping
  • Save the integration and Activate
  • Let’s test the integration now. Open POSTMAN tool and hit the REST service URL
  • See the inbox, an email notification should reach with an attachment