sending attachments using javamail
3 posts in topic
Flat View  Flat View

Posted By:   Sanjit_Nair
Posted On:   Saturday, January 26, 2002 07:33 AM

how do I write a mail program (in servlets) such that,
a client who accesses my program (servlet) can attach a file residing on his local machine .
Currently,I am able to attach only files residing on my server .......
...can anyone please help me out (atleast some hints please....)

Re: sending attachments using javamail

Posted By:   Anonymous  
Posted On:   Saturday, February 2, 2002 08:52 AM

I have finished like this, the client can choose the file to be the attachment from their machine,
and then my program send the mail with the attachment without save it on server size file system.

1. use the request.getInputStream() in your servlet,
and parse the data to get the necessary infomation of the upload file
like filename, file data(bytes[]), content type ..etc.

2. follow the send mail with attachments step, constructs a new mail, but in attachment step
use the ByteArrayDataSource (you can find this in java mail's example)

for example:

you have a upload file as attachment, with the following data

byte[] content = ...;
String filename = ...;
String content_type = ....;

MimeBodyPart mbp = new MimeBodyPart();
ByteArrayDataSource ds = new ByteArrayDataSource(content, content_type);
mbp.setDataHandler(new DataHandler(ds));

then you have finished an attachment of the mail.

Re: sending attachments using javamail

Posted By:   Burcu_x  
Posted On:   Friday, February 1, 2002 04:48 AM


Re: sending attachments using javamail

Posted By:   SookFan_Le  
Posted On:   Tuesday, January 29, 2002 09:06 PM

Probably you might like to refer to the Javamail tutorial at this url under the topic of working with attachments: http://developer.java.sun.com/developer/onlineTraining/JavaMail/

Hope this might help you :)

About | Sitemap | Contact