Skip to main content

I am handling different attachment types through SMTP connector.

 

The attachment content is coming has part of payload.

 

Below is array of JSON sample payload for attachments. So, here CSV and other formats are working fine but PDF format is not able to open even though mule is not throwing any error.

"attachments": [

{

"attachmentName": "ourholidays.csv",

"attachmentContent": "fdgdfgfdg",

"attachmentType": "application/csv"

},

{

"attachmentName": "ourholidays.pdf",

"attachmentContent": "dfgfdgdfgd",

"attachmentType": "application/pdf"

}

]

 

here is the code snippet for attachment

 

<sub-flow name="Attachment_Subflow">

<choice doc:name="Choice">

<when expression="payload.attachments != null && payload.attachments.size() > 0">

<set-variable variableName="attaches" value="#&nbsp;[new java.util.HashMap()]" doc:name="Variable" />

<foreach collection="#&nbsp;[payload.attachments]" counterVariableName="x" doc:name="For Each">

 

<set-attachment attachmentName="#&nbsp;[payload.attachmentName]" value="#&nbsp;[org.apache.commons.codec.binary.Base64.encodeBase64(payload.attachmentContent.getBytes())]" contentType="#&nbsp;[payload.attachmentType]" doc:name="Attachment" />

<expression-component doc:name="Expression"><![CDATA[java.util.Set keys = message.outboundAttachments.keySet();

for(Object key:keys){

flowVars.attaches.put(key, message.outboundAttachments.get(key));}] ]></expression-component>

</foreach>

<expression-component doc:name="Expression"><![CDATA[message.outboundAttachments.putAll(flowVars.attaches);] ]></expression-component>

</when>

<otherwise>

<logger message="DEFAULT FLOW" level="INFO" doc:name="Logger" />

</otherwise>

</choice>

<flow-ref name="SMTP_Flow" doc:name="SMTP_Flow" />

</sub-flow>

 

We tried both encoding and decoding the attachment content even without doing that also . nothing is working even though attachment successfully attached to email not able to open PDF s attachment

 

When PDF coming as file to inbound message flow it is working by keeping file to byte array node between file connector and attachment node ,

Regards,

Sudeepthi

0/9000