cancel
Showing results for 
Search instead for 
Did you mean: 

Attachments and content in Mail receiver adapter

former_member560382
Participant
0 Kudos

Hi guys,

I have an SOAP->Mail scenario and I have a problem with handling attachments and content in the same email. The issue is, that if I want to keep attachments which are sent with SOAP request, I need to check "Keep attachments" checkbox in receiver mail communication channel.

However, technically, Payload is also an attachment and the adapter adds payload also as an attachment instead keeping the body in the mail body.

So finally I end up with an email having no body and original attachment and payload attachment.

Any ideas how I could set up the adapter so I get a body with a proper content and required attachments?

I use Mail package and am on 7.31 version.

Thanks guys in advance,

Peter

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

Hi Peter

Unfortunately, this is indeed the behavior of the mail receiver adapter.

Therefore you'd need some custom development to get it to work, i.e. have an email body with attachments.

Following blog shows an example of constructing the MIME content of the email via Java mapping. It does not use Mail Package since Mail Package is deprecated.

However, if you insist on using Mail Package, you can refer to the link within the above blog as well as the solution in the following thread.

Regards

Eng Swee

Answers (3)

Answers (3)

former_member560382
Participant
0 Kudos

Below is the UDF I use to generate the Content element.

Sender CC I use soap sender - keep attachments needs to be checked

Receiver CC - Mail, mailpackage, keep attachments UNCHECKED

use the links from above to see how the content should be generated. Important is , that boundary in the content uses additional "--" String.

UDF has one parameter - boundary - in my case it is "--AaZz".

One input field - which is mapped to mailbody parameter - that is what I want to have in the mail body and not as an attachment.

GlobalContainer globalContainer = container.getGlobalContainer();

InputAttachments inputAttachments = globalContainer.getInputAttachments();

String nl = "\r\n";

String result = "--" + boundary + nl + "Content-Type: text/plain; charset=UTF-8" + nl + "Content-Disposition: inline" + nl + nl+ mailbody;

if(inputAttachments.areAttachmentsAvailable())

{

     Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);

     Iterator<String> IDsIterator = CollectionIDs.iterator();

     while(IDsIterator.hasNext())

     {

          String AttachmentID = IDsIterator.next();

          Attachment attachment = inputAttachments.getAttachment(AttachmentID);

          String ct = attachment.getContentType();

          result +=  nl + nl + "--" + boundary + nl;

          result +=  "Content-Transfer-Encoding: base64" + nl;

          result +=  "Content-Type: " + ct + nl;

          result +=  "Content-Disposition: attachment; filename=" + ct.substring(ct.indexOf("name")+5);

          result +=  nl + nl + attachment.getBase64EncodedContent();

      }

}

return result + nl + nl + "--" + boundary + "--";

engswee
Active Contributor
0 Kudos

Hi Peter

First of all, thank you for sharing back the solution that worked for you with the rest of the community.

Secondly, I need to apologize for my previous reply which sent you off to develop custom UDF to achieve your requirement. I've been debugging the mail adapter and figured out an alternative solution (that I've not been aware of before) that does not require custom Java coding. I've written more about it in the following article.

Regards

Eng Swee

former_member560382
Participant
0 Kudos

Hi Eng Swee,

nice blog. I'm though not sure if it would work for me as I need to generate the recipient's email address dynamically.

Br,

Peter

engswee
Active Contributor
0 Kudos

Hi Peter

I updated my post with a simple example of how the address can be set dynamically using Dynamic Configuration.

Not suggesting that you change your design now since you already have it working, more for FYI

Regards

Eng Swee

apu_das2
Active Contributor
0 Kudos
vicky20691
Active Contributor
0 Kudos

Hi Peter,

When you are sending message from SOAP to mail, then what should go as mail body and what should go as attachment.

Do you want the same message to go as body as well as attachment?

Regards,

Vikas

former_member560382
Participant
0 Kudos

Hi, original attachments should be as attachments and content set in the Content element of a Mailpackage should be in the body.

I dont want to have the payload as an attachment.

Peter

vicky20691
Active Contributor
0 Kudos

Hi Peter,

Thats easy, when you select Keep attachment and use mailpackage then there will be a dropdown for content encoding,

If it is none, just make it base64, it should solve your problem.

Regrds,

Vikas

former_member560382
Participant
0 Kudos

Unfortunately it didn't. I have the same result - nothing in the body and 2 attachments, original one and the content of the COntent element in attachment named MainDocument.xml  (and it is not unfortunately an XML at all.. which is strange nehaviour of standard adapter)

Any other suggestions please?

Thanks,

Peter

vicky20691
Active Contributor
0 Kudos

Hi Peter,

In the receiver mail channel please check the following

1. Message Protocol- it should be XIPAYLOAD

2. Keep Attachments checked

3. Use mail package checked

4. Content encoding - None (by default it will be base64 change it to none).

Regards,

Vikas