You might have come across a scenario, where it is required to send multiple attachments in Email using CPI Mail receiver adapter, As we have only option to send an attachment either by content of body or Header. Also we can not use header for sending large files as adapter has a size limitation of header content, If size exceeds the header allowable limit, Interface will fail. So only option left is to send body content as an attachment.
To overcome this limitation, we can use Groovy script to send multiple files as an attachment. There is a detailed blog on this topic by 7a519509aed84a2c9e6f627841825b5a ,which you can refer.
import org.apache.camel.impl.DefaultAttachment
import javax.mail.util.ByteArrayDataSource
def Message processData(Message message) {
//Body
def body = message.getBody();
def id = map.get("requestData");
def bytes = map.get("requestData");
def dataSource = new ByteArrayDataSource(bytes, 'Text/CSV') //Set MIME type
def attachment = new DefaultAttachment(dataSource)
message.addAttachmentObject("Request.txt", attachment) //Add request attachment
id = map.get("responseData");
bytes = map.get("responseData");
dataSource = new ByteArrayDataSource(bytes, 'Text/CSV')
attachment = new DefaultAttachment(dataSource)
message.addAttachmentObject("Response.txt", attachment)
return message
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |