cancel
Showing results for 
Search instead for 
Did you mean: 

Need to send the zip file to mail as an attachment

allamudi_loordh
Active Participant
0 Kudos

i want to pick the zip file which consists some 2,3 files inside it. and send as it is to mail as an attachment.what i did is

i have taken one zip file,,, "testing.zip" inside it i have "test1.txt" & "test2.csv"

i created sender CC ,,in that i used module payloadzipbean and unzipped and called the file adapter.. created reciever CC as mail ..used same payload module now here i zipped all the payloads.

Result..i see the attachment coming as "test1.txt.zip" ..here i can see inside this zipfile my original file names as "test1.txt"&"test2.csv" as i enabled ASMA in both CC.

issues:i am unable to get the original file name like "testing.zip" ,,

can anyone help me in this.

Regards,

Loordh

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Please check this thread

Pick ur zipped original file using file adapter without conversion.

/people/william.li/blog/2006/09/08/how-to-send-any-data-even-binary-through-xi-without-using-the-integration-repository

Then use reciever mail adapter with PayloadSwapBean to send the original file as attachment.

Regards

Raj

Edited by: raj sharma on Sep 13, 2011 5:38 AM

naveen_chichili
Active Contributor
0 Kudos

Hi,

Use PayloadZipBean so that you would be able to send the zip as an attachment.

/people/stefan.grube/blog/2007/02/20/working-with-the-payloadzipbean-module-of-the-xi-adapter-framework

Regards,

Naveen

Former Member
0 Kudos

Hi,

Check this link

https://wiki.sdn.sap.com/wiki/display/XI/AdapterModulePI7.0GetAttachmentName

allamudi_loordh
Active Participant
0 Kudos

Hi ramesh,

thnks for response..as i am using sender as file adapter is that module is sufficient?

Former Member
0 Kudos

Hi,

Yes.

You use File sender Adapter for picking the file, use the code depicted in the blog as adapter module for receiver mail adapter and include it after mail adapter.

Read the below instruction

This adapter module can be used in sender mail adapter.

It reads the attachment name from the content type of the MIME header and writes

it to an adapter specific message attribute (ASMA). Put this module after the standard

mail adapter module If the incoming mail has several parts,

then the PayloadSwapBean should be used before this module.

Hope it helped you.

Ramesh

allamudi_loordh
Active Participant
0 Kudos

As discussed with my team,,the requirements are like follows i need to pick the zip file and send as attachment to mail .i am using mail package at target side bcoz i need to generate to,cc,bcc ..it may change in future also ..so i want to go for java mapping or udf for this..kindly can anyone give me an idea to proceed.

allamudi_loordh
Active Participant
0 Kudos

Hi all,

as i posted last time my requirement ,i am going with java mapping for my scenario. i am using this code .

http://wiki.sdn.sap.com/wiki/display/XI/Dynamicfilenameforpass-through+scenario

this is working perfect for zip file (file to file) scenario. but my scenario is file to mail ..as i need to send this to mail package there it is throwing error.i am getting "zip file name as attachment properly but when i try to open it is giving error in zip file." this is what i modied code ..i am able to see my messge in sender CC and reciever CC..any java experts please help on this.

try {

// create XML structure of mail package

String output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"

+ "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"

+ "<Subject>" + mailSubject + "</Subject>"

+ "<From>" + mailSender + "</From>"

+ "<To>" + mailReceiver + "</To>"

+ "<Content_Type>multipart/mixed; boundary=\"" + boundary + "\"</Content_Type>"

+ "<Content>";

out.write(output.getBytes());

// create the declaration of the MIME parts

//First part

output = "--" + boundary + CRLF

+ "Content-Type: text/plain; charset=UTF-8" + CRLF

//+ "Content-Transfer-Encoding: 8bit" + CRLF

+ "Content-Disposition: inline" + CRLF + CRLF

+ mailContent + CRLF

//Second part

+ "--" + boundary + CRLF

+ "Content-Type: Application/zip; name=" + attachmentName + CRLF

//+ "Content-Transfer-Encoding: base64" + CRLF

+ "Content-Disposition: attachment; filename=" + attachmentName + CRLF + CRLF;

out.write(output.getBytes());

//Source is taken as attachment

copySource(in, out);

out.write("</Content></ns:Mail>".getBytes());

} catch (IOException e) {

throw new StreamTransformationException(e.getMessage());

}}

protected static void copySource(InputStream in, OutputStream out)

throws IOException {

byte[] bbuf = new bytehttp://in.available();

int bblen = in.read(bbuf);

if (!(bblen < 0)) {

//String sbuf = new String(bbuf);

//String encoded = Base64.encode(sbuf);

// replace all control characters with escape sequences

//sbuf = sbuf.replaceAll("&", "&");

//sbuf = sbuf.replaceAll("\"", """);

//sbuf = sbuf.replaceAll("'", "&apos;");

//sbuf = sbuf.replaceAll("<"<");

//sbuf = sbuf.replaceAll(">", ">");

out.write(bbuf);}}

allamudi_loordh
Active Participant
0 Kudos

hi all,

if any approach other than adapter modules are welcome.

thanks,

stefan_grube
Active Contributor
0 Kudos

You cannot use mail package for a binary attachment liek zip.

Use Java mapping to create a new attachment with the content of the original payload and create a new payload with the mail content. You need PI 7.1 to create an attachment with Java mapping, otherwise you need an adapter module.

allamudi_loordh
Active Participant
0 Kudos

Thnaks for all who gave me some ideas..i have finished this ..the procedure is i have encoded incoming zip file into BASE64 and passed to mail package as content.so i have used 2 mappings ...1.java mapping 2.message mapping.

java mapping output will go to input to message mapping...in message mapping target structure will be mail package....solved for to,cc,bcc in message mapping.