Just look at JavaMail API

> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Nishit Trivedi
> Sent: Thursday, March 08, 2001 2:48 PM
> To: [EMAIL PROTECTED]
> Subject: Re: How to send attachment by email through JSP?
>
>
> in your java code do this:
>
> Set this variable as "true"
>
>  boolean sendMultipart = true;
>
> Set all variables :
> String to="<mailto>";
> String from="<mail from>"
> String[] filesToBeAttached =
> {"C:"+File.separator+"XmlDTD.ppt","C:"+File.separator+"Introductio
> n.xml","C:
> "+File.separator+"Introduction.xsl"};
>
> etc...
>
> do this:
> ---------------------------------
> try {
>    // create a message
>    Message msg = new MimeMessage(session);
>
>    // set the from
>    InternetAddress from = new InternetAddress(mailFrom);
>    msg.setFrom(from);
>    InternetAddress[] address = {new InternetAddress(mailTo)};
>    msg.setRecipients(Message.RecipientType.TO, address);
>    msg.setSubject("JavaMail APIs Test");
>    if (!sendMultipart) {
>             // send a plain text message
>             msg.setContent(msgText, "text/plain");
>    }
>    else {
>             // send a multipart message
>
>             //create the Multipart and its parts to it
>             Multipart mp = new MimeMultipart();
>
>             // create and fill the first message part
>             MimeBodyPart mbp1 = new MimeBodyPart();
>             mbp1.setContent(msgText, "text/plain");
>             mp.addBodyPart(mbp1);
>
>             //mbp2.setContent(msgText2, "text/plain");
>
>           //attach the file to the message
>             for(int i=0;i<filesToBeAttached.length;i++){
>                      // create and fill the second message part
>                    MimeBodyPart mbp2 = new MimeBodyPart();
>                    javax.activation.FileDataSource fds = new
> javax.activation.FileDataSource
> (filesToBeAttached[i]);
>                      mbp2.setDataHandler(new
> javax.activation.DataHandler(fds));
>              mbp2.setFileName(filesToBeAttached[i]);
>                      mp.addBodyPart(mbp2);
>             }
>
>             // add the Multipart to the message
>             msg.setContent(mp);
>    }
>    Transport.send(msg);
>    return "successfully sent email";
> } catch (MessagingException mex) {
>         mex.printStackTrace() ;
> }
> -------------------------------------------
>
> Nishit
> -----Original Message-----
> From: Louie Tao [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, March 08, 2001 5:32 PM
> To: [EMAIL PROTECTED]
> Subject: How to send attachment by email through JSP?
>
>
> Hello,
>
> we can send regular email.
> However, we need to handle  any kind of files (eg text file, jpg file etc)
> in the attachment if there is an attachment.
>
> Any ideas or a few lines of code  will be appreciated
>
> thanks in advance
>
> ==================================================================
> =========
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> DIGEST".
> 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
>
> ==================================================================
> =========
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set
> JSP-INTEREST DIGEST".
> 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
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
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