you  have to make a multi-part message and set the second part of it as
the file.  construct the rest of the message as normal(from, to, etc.):


MimeMessage msg = new MimeMessage(session);

MimeBodyPart mimepart1 = new MimeBodyPart();
mbp1.setText(msgText1);

MimeBodyPart mimepart2 = new MimeBodyPart();

FileDataSource fds = new FileDataSource(filename);
mimepart2.setDataHandler(new DataHandler(fds));
mimepart2.setFileName(fds.getName());

Multipart multi = new MimeMultipart();
multi.addBodyPart(mimepart1);
multi.addBodyPart(mimepart2);

msg.setContent(multi);



Bhuvaneswari Palanivel wrote:
>
> Hi,
>
> I am using Java Mail API for sending mail. Is there any method or something
> to send a email with an attachment?
> Please refer some site name.
>
> Thanks,
> Bhuvana
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

--
I18n group,
Sun Microsystems Ireland.
Phone: 8199751, x19751

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to