Enter your keyword

post

Leverage Microsoft Email Adapter to send email with attachment in Oracle Integration Cloud (OIC) (Part-2)

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

{
“To”:”recipients@example.com”,
“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 https://outlook.office.com/Mail.ReadWrite 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 https://outlook.office.com/Mail.Send 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
{
“To”:”recipients@example.com”,
“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
Source
Target
Body
Body -> Content
To
ToRecipients -> EmailAddress -> Address
Subject
Subject
As per the Microsoft Document, to send an attachment in an email an Attachments object is required in the https://outlook.office.com/api/v2.0/me/sendmail 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
SENDATTACHMENTNOTIFICATION_01.00.0000.iaricspackageprojectSENDATTACHMENTNOTIFICATION_01.00.0000resourcesapplication_15inbound_16resourcegroup_17SendAttachments_REQUEST.wsdl
  • Search complex element of type “messageResource.definitions.messageResource” and add below element
<xs:element name=”Attachments” minOccurs=”0″ maxOccurs=”unbounded”>
            <xs:complexType>
                        <xs:complexContent>
                                    <xs:extension base=”messageResource.definitions.attachments”>
                                                <xs:attribute name=”odata.type” />
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
</xs:element>
  • Add below complex element in the WSDL file
<xs:complexType name=”messageResource.definitions.attachments”>
            <xs:annotation>
                        <xs:appinfo>
                                    <ns1:custom>false</ns1:custom>
         </xs:appinfo>
    </xs:annotation>
    <xs:sequence>
                        <xs:element name=”Name” type=”xs:string” />
        <xs:element name=”ContentBytes” type=”xs:string” />
    </xs:sequence>
</xs:complexType>
  • 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

Some Toughts (21)

  1. added on 2 Oct, 2018
    Reply

    HI Ankur,

    I am getting 415 Unsupported Media Type Error on hitting the REST URL.
    Can you suggest me any reason for this.

  2. added on 3 Oct, 2018
    Reply

    Hi,
    It look like you have added wrong Content-Type header. Please correct the same and send the request again.

    Regards,
    Ankur

  3. added on 3 Oct, 2018
    Reply

    What Contetnt -type should i use?

  4. added on 8 Oct, 2018
    Reply

    Hi Ankur,

    Still stuck. Can you help me in this.
    When i use Multipart/Form-data I am getting the following error.
    "exception occurred while translating the request from native to xml"

  5. added on 8 Oct, 2018
    Reply

    Hi Hemant,
    You can find out the content type by entering the service endpoint into the browser till /metadata.

    Can you send the exact error which you are getting from the ICS logs along with the IAR and request which you are trying to make.
    Regards,
    Ankur

  6. added on 12 Oct, 2018
    Reply

    Hi Ankur,

    I have followed all the steps. The error i am getting is
    OSB-380001: 403 :Application Error

    OK

    Could you pls give a pointer on this.

    Regards,
    Vivek

  7. added on 12 Oct, 2018
    Reply

    OSB-380001: 403 :Application Error

    OK

  8. added on 12 Oct, 2018
    Reply

    ErrorMessageSubmissionBlocked","message":"Cannot send mail. Follow the instructions in your Inbox to verify your account., WASCL UserAction verdict is not None. Actual verdict is HipSend, ShowTierUpgrade."}}]]> :Application Error

  9. added on 16 Nov, 2018
    Reply

    This comment has been removed by the author.

  10. added on 16 Nov, 2018
    Reply

    This comment has been removed by the author.

  11. added on 16 Nov, 2018
    Reply

    This comment has been removed by the author.

  12. added on 28 Jan, 2019
    Reply

    Hi Hemant/Ankur,
    were we able to figure out above issue, i am facing same issue.

  13. added on 2 Feb, 2019
    Reply

    The IT professionals generally face the most challenging roles in the decision making jobs. In the networking field many Microsoft Operating System Software are implemented through the Microsoft Certified Systems Engineer certification (MCSE) on the desktop and server.
    MCSE Training London

  14. added on 11 Mar, 2019
    Reply

    I am also facing this issue. Was there any resolution? Media-Type is multipart/mixed as defined in REST connection.

  15. added on 11 Mar, 2019
    Reply

    I changes the order of headers- authorization and then content-type and it worked! previously it was content-type and then authorization. Strange!

  16. added on 15 Mar, 2019
    Reply

    When i send a request through post man i am getting this error

    {
    "type": "10.4.1",
    "title": "exception occurred while translating the request from native to xml.",
    "detail": "oracle.cloud.connector.api.CloudInvocationException: ORABPEL-15235nn",
    "o:errorCode": "TRANSLATION-ERROR-00",
    "o:errorDetails": [
    {
    "type": "NA",
    "instance": "NA",
    "title": "NA",
    "o:errorPath": "NA",
    "o:errorCode": "NA"
    }
    ]
    }

  17. added on 8 Apr, 2019
    Reply

    Some problems are quite unavoidable due to which it also becomes unavoidable for your computer to escape from them.reset windows 10 password

  18. Anonymous
    added on 10 Apr, 2019
    Reply

    Seems like postman generates an additional header called "content-type", sets it to ""multipart/form-data; boundary=—WebKitFormBoundary…" which is apparently incorrect on top of the correct Content-Type = multipart/mixed and causes the 415 unsupported media type errors.
    I submitted the POST request in code without the additional content-type header and was able to hit the REST endpoint successfully… but when it reached the MS Outlook adapter I got error 400, ErrorRequiredPropertyMissing, Required property is missing. Any resolution?

  19. added on 10 May, 2019
    Reply

    Enjoyed every bit of your article post.Really looking forward to read more. Much obliged. microsoft toolkit 2.6.6 free download

  20. added on 8 Jul, 2019
    Reply

    i found that is an informative and tasty publicize so i think consequently it is honestly beneficial and knowledgeable. i'd with to thank you for the efforts you've got made in writing this article. Error 0x80070185

  21. added on 20 Jul, 2019
    Reply

    I felt very happy while reading this site. This was really very informative site for me. I really liked it. This was really a cordial post. Thanks a lot!. email search

Leave a Reply

Your email address will not be published.