Skip to main content

#Payload.attachment0 discussing

Hi,

I have a dynamic payload,

Would like to send the email with dynamic attachments while looping through the payload array.

My sample payload below

{

"attachments": [{

"fileType": "txt",

"fileName": "textattachment.txt",

"values": "This is the First email text attachment for NG"

}

{

"fileType": "txt",

"fileName": "sectextattachment.txt",

"values": "This is the Secondemail text attachment for NG"

}

]

}

 

Attachment payload will be dynamic and some time it can have single attachment and some time it has multiple attachments with txt ,csv types.

In single email I want to have all the attachments of payload

How I can loop through this payload and send the attachments.

Is it possible to Payload Map inside Send connector attachment section?.

 

Thanks in advance

--

Naveen G

1 answer
  1. Feb 1, 2022, 10:40 PM

    I just saw this question, I am sure you might have resolved it. Just adding my response in case anyone else looking for.

     

    //Create an empty map

    <set-variable value="#{}" doc:name="Set Variable" doc:id="4174b647-2b19-4803-bd16-f88cb7e910d1" variableName="fileList"/>

     

    //iterate over attachement list

    <foreach doc:name="For Each" doc:id="c166af5e-5c74-4157-90a4-e23cea3102f5" collection="#payload.attachment">

    <file:read doc:name="Read" doc:id="330f2166-d2b1-43f8-be7c-de132f92b7c7" config-ref="File_Config" path="#payload.name" target="tempAttach" />

    <ee:transform doc:name="Transform Message" doc:id="6610f4eb-3ce2-4832-9ef5-72d3f9492bff">

    <ee:message>

    </ee:message>

    <ee:variables>

    <ee:set-variable variableName="fileList"><![CDATA[%dw 2.0

    import * from dw::core::Binaries

    output application/java

    ---

    vars.fileList ++ {

    (payload.name) : toBase64(vars.tempAttach)

    }]]></ee:set-variable>

    </ee:variables>

    </ee:transform>

    </foreach>

     

    ------------------------------------------

     

    in SMTP connector use following to iterate the map and add attachement

    %dw 2.0

    output application/java

    ---

    vars.fileLIst mapObject ((value, key, index) -> 

    {

       (key) : value

    })

0/9000