cancel
Showing results for 
Search instead for 
Did you mean: 

Email with attachment

Former Member
0 Kudos

Hello experts,

I have a specific requirement with regard to email. I get an xml file which contains the "to" address and also the location path of a file. I need to send a mail to that address with the file specified in the path as attachment. How do I go about it?

Many thanks,

RR

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Along with the other suggestions, please check this: /people/michal.krawczyk2/blog/2005/03/07/mail-adapter-xi--how-to-implement-dynamic-mail-address

Thanks,

baskar_gopalakrishnan2
Active Contributor
0 Kudos

This could be simple file to mail scenario.

create UDF to read the file from specified location and return the output as string and map it to target mail structure field content element.Map the to field address from the file to to mail address tag of target structure. You need to send mail as attachment. Refer the below link for configuring mail scenario. Use message protocol option XIALL in the receiver mail adapter to send payload as attachment.

Refer this [link|http://www.riyaz.net/blog/xipi-sending-emails-using-xi-mail-adapter/technology/sap/83/]

former_member854360
Active Contributor
0 Kudos

Hi,

Create a XML file to Mail scenarion using mail package structure in receiver side.

Use this blog to create mail attachment in UDF in target mail package structure.

XI Mail Adapter : Dynamically building attachment and message body content using a simple UDF

/people/samuel.chandrasekaran2/blog/2008/10/06/xi-mail-adapter-dynamically-building-attachment-and-message-body-content-using-a-simple-udf

and read the file content of the path specified in your input XML in UDF itseldf and map it to content field of mail structure .

You can connect to NFS by udf java code and read the content of the file .

Refer ths blog on read file from UDF.

http://wiki.sdn.sap.com/wiki/display/XI/DifferentwaystokeepyourInterfacefromprocessingduplicate+files

http://www.roseindia.net/java/beginners/java-read-file-line-by-line.shtml

Former Member
0 Kudos

Hello all,

Many thanks for the responses.

I have used the method mentioned by Debashish to read the binary file and attach it to the multipart content. I am reading the content of a .doc file and trying to send it as an attachment. The issue I am facing now is that the target file/attachment is showing garbage content for images and non text parts. I am guessing this has something to do with the encoding. Can anyone throw any light on this as to how it can be handled?

RR

former_member854360
Active Contributor
0 Kudos

Hi ,

set the proper MIME Type for Image.

MIME Type File Extension

image/bmp bmp

image/cis-cod cod

image/gif gif

image/ief ief

image/jpeg jpe, jpeg, jpg

image/pipeg jfif

image/pjpeg jpeg

image/png png

image/svg+xml svg

image/tiff tif, tiff

image/x-cmu-raster ras

image/x-cmx cmx

image/x-icon ico

image/x-png png

image/x-portable-anymap pnm

image/x-portable-bitmap pbm

image/x-portable-graymap pgm

image/x-portable-pixmap ppm

image/x-rgb rgb

image/x-xbitmap xbm

image/x-xpixmap xpm

image/x-xwindowdump xwd

http://www.w3schools.com/media/media_mimeref.asp

See sample MIME with DOC and image in this Example

http://www.ietf.org/rfc/rfc2387.txt

Also in receiver mail adapter select NO ENCODING

Former Member
0 Kudos

Hello Debashish,

I have set the content type to application/pdf. There is no encoding at the receiver side either. However the target pdf comes up as blank. It doesnt show any content.

Why cant the content type be defined as binary? Wont binary to binary copy just create a replica of the source file?

Thanks,

RR

former_member854360
Active Contributor
0 Kudos

Hi

can you try to set MIME type for PDF as APPLICATION/OCTET-STREAM?

Can you also share the code which you are using to read PDF from file system?

Former Member
0 Kudos

I have tried with octect-stream as well. Got the same empty output. Hope its not case sensitive.

The code I am using to read from binary to string is given below:

File file = new File(fileName);

char[] buffer = null;

try {

BufferedReader bufferedReader = new BufferedReader(

new FileReader(file));

buffer = new char[(int)file.length()];

int i = 0;

int c = bufferedReader.read();

while (c != -1) {

buffer[i++] = (char)c;

c = bufferedReader.read();

}

} catch (FileNotFoundException e) {

;

} catch (IOException e) {

;

}

return new String(buffer);

Thanks,

RR!

Former Member
0 Kudos

Hello experts!

Any clue on this. I have tried quite a few things but nothing seems to be working. There is no problem transferring text files but for the binary files, I cant seem to transfer it properly.

I also tried the setting given in the blog

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/6d967fbc-0a01-0010-4fb4-91c6d38c5...

Though the file is picked up, it is corrupted at the receiver side. Is there any encoding issues to be considered while converting binary to string and then back to binary?

Thanks,

Rajith

former_member854360
Active Contributor
0 Kudos

Hi ,

PDFs may contain binary data and chances are it's getting mangled when you do ToString

FileInputStream inputStream = new FileInputStream(sourcePath);

int numberBytes = inputStream .available();

byte bytearray[] = new byte[numberBytes];

inputStream .read(bytearray);

String str = Base64.encode(bytearray); //buffer);

then String will be Base64 encoded