sorry nishit, the code you gave me didn't work either. tell me something, besides
downloading the JavaMail & JAF and then adding the activation.jar & mail.jar to the
Classpath ... is there anything else which is needed to be done or require on the
system for Mail to be sent??
SupremeBeing
>Date: Fri, 11 May 2001 14:43:19 -0400
>From: Nishit Trivedi <[EMAIL PROTECTED]>
>SUBJECTTo: [EMAIL PROTECTED]
>
>hi..
>Following code is used to send email (using JavaMail api)
>thru one of my xml apps..try this...remove all
>xml stuff and make it simple java program (or function)..
>this code facilitates also sending attachments with email...
>--------------------------------------------------
> <xsp:include>javax.mail.*</xsp:include>
> <xsp:include>javax.mail.internet.*</xsp:include>
> </xsp:structure>
>
> <xsp:logic>
> private static String SendMailTest() {
> String mailTo = "[EMAIL PROTECTED]";
> String mailFrom = "[EMAIL PROTECTED]";
> String mailHost = "corporate.planet.net";
> boolean debug = true; // change to get more information
> String msgText = "This is just a test mail.\nThis email is from
>JavaMail app.";
> String msgText2 = "You can write more lines from here.";
> String[] filesToBeAttached =
>{"C:"+File.separator+"XmlDTD.ppt","C:"+File.separator+"Introduction.xml","C:
>"+File.separator+"Introduction.xsl"};
>
> //boolean sendmultipart = Boolean.valueOf(debug).booleanValue();
> boolean sendmultipart = true;
> // set the host
> Properties props = new Properties();
> props.put("mail.smtp.host", mailHost);
> // create some properties and get the default Session
> Session session = Session.getDefaultInstance(props, null);
> session.setDebug(debug);
> 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");
>
> <![CDATA[
> //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() ;
> }
> return "unsuccessful to send email";
> }
> </xsp:logic>
>--------------------------------
>
>hope this helps you..
>
>Nishit
>-----Original Message-----
>From: Supreme Being [mailto:[EMAIL PROTECTED]]
>Sent: Friday, May 11, 2001 2:24 PM
>To: [EMAIL PROTECTED]
>Subject: JavaMail with JSP
>
>
>i succesfully downloaded the JavaMail and JAF from sun's site in order to
>use them with my JSP which i'm running on JRun Studio on my win98 PC. i
>added the CLASSPATH (in autoexec.bat) as told by the docs along with them.
>Now what? coz nothing is working. I have this HTML page and a JSP page which
>is supposed to send email...but it's not working... i'm getting a
>java.SendMailException error. what do i have to do? is there something i
>missed?
>The codes i'm using are as follows :
>[The HTML Page] : javamail.html
>
><FORM action="sendjavamail.jsp" method="post">
> <TABLE>
> <TR>
> <TD width="50%"><font face="arial" color=#ffdead size=2>
> To:<BR><INPUT name="to" size="25">
> </TD>
> <TD width="50%"><font face="arial" color=#ffdead size=2>
> From:<BR><INPUT name="from" size="25">
> </TD>
> </TR>
> <TR>
> <TD colspan="2"><font face="arial" color=#ffdead size=2>
> Subject:<BR><INPUT name="subject" size="50">
> </TD>
> </TR>
> <TR>
> <TD colspan="2"><font face="arial" color=#ffdead size=2>
> <P>Message:<BR><TEXTAREA name="text" rows=5 cols=30>
------------------------------------------------------------
Are you a Hoboe? Hobnob at http://www.hoboe.com
Click here -> http://www.hoboe.com Global Mail Access
===========================================================================
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