The preferred way to send email from Java applications is by using the
JavaMail package (java.sun.com/products/JavaMail).

<promotion>
Our forthcoming book "Professional Java Programming with XML", WROX, January
2000, will have a SimpleMail.jsp page with an associated bean that do a
variety of email tasks.
</promotion>

Alexander Nakhimovsky tel 315-824-7586
Computer Science Dpt  fax 315-824-7004
Colgate University    [EMAIL PROTECTED]
Hamilton NY 13346     [EMAIL PROTECTED]




> -----Original Message-----
> From: Jacob Madsen [mailto:[EMAIL PROTECTED]]
> Sent: Monday, November 01, 1999 8:10 AM
> Subject: Re: Sending email from JSP
>
>
> Thank you, that seems to work, except for the fact, that the
> FROM and TO
> portions of the message header are missing in all messages...
> I can't figure
> out why... Can you help?
>
> Jacob
> ----- Original Message -----
> From: R. Jarett Kulm <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: 29. oktober 1999 18:53
> Subject: Re: Sending email from JSP
>
>
> > Description: This is a script to send Email via Java Server
> Pages.  This
> has
> > been tested to work in Oracle Application Server 4.0.8.1.0
> w/ JSP addon.
> >
> > ================= Start FormMail.html =======================
> >
> >
> > <html>
> >
> > <head>
> > <meta http-equiv="Content-Type"
> > content="text/html; charset=iso-8859-1">
> > <title></title>
> > </head>
> >
> > <body bgcolor="#008080">
> >
> > <p align="center"><br>
> > <font color="#80FF80" size="5">Send Mail using JSP</font></p>
> >
> > <form action="FormMail.jsp" method="POST">
> >     <div align="center"><center><table border="0" cellpadding="2"
> >     cellspacing="0">
> >         <tr>
> >             <td bgcolor="#000080"><font color="#00FFFF"
> >             face="Arial">From</font></td>
> >             <td bgcolor="#008080"><font face="Arial"><input
> >
> >             type="text" size="20" name="from"></font></td>
> >             <td bgcolor="#008080"><font color="#80FF00"
> >             face="Arial">[EMAIL PROTECTED]</font></td>
> >         </tr>
> >         <tr>
> >             <td bgcolor="#000080"><font color="#00FFFF"
> >             face="Arial">To</font></td>
> >             <td bgcolor="#008080"><font face="Arial"><input
> >
> >             type="text" size="30" name="to"></font></td>
> >             <td bgcolor="#008080"><font color="#80FF00"
> >             face="Arial">[EMAIL PROTECTED]</font></td>
> >         </tr>
> >         <tr>
> >             <td bgcolor="#000080"><font color="#00FFFF"
> >             face="Arial">Subject</font></td>
> >             <td bgcolor="#008080"><font face="Arial">
> >             <input type="text" size="40" name="subject"></font></td>
> >             <td bgcolor="#008080"><font color="#80FF00"
> >             face="Arial">Hi There!</font></td>
> >         </tr>
> >         <tr>
> >             <td bgcolor="#000080"><font color="#00FFFF"
> >             face="Arial">Use Server</font></td>
> >             <td bgcolor="#008080"><font face="Arial"><input
> >
> >             type="text" size="40" name="server"
> > value="smtp.domainname.com"></font></td>
> >             <td bgcolor="#008080"><font color="#80FF00"
> >             face="Arial">smtp.whereever.com</font></td>
> >         </tr>
> >         <tr>
> >             <td valign="top" bgcolor="#000080"><font
> >
> >             color="#00FFFF" face="Arial">Msg Body</font></td>
> >             <td bgcolor="#008080"><textarea name="msgbody"
> >             rows="20" cols="38"></textarea></td>
> >             <td bgcolor="#008080">&nbsp;</td>
> >         </tr>
> >         <tr>
> >             <td bgcolor="#008080">&nbsp;</td>
> >             <td align="center" bgcolor="#008080"><input
> >
> >             type="submit" name="B1" value="Submit"></td>
> >             <td bgcolor="#008080">&nbsp;</td>
> >         </tr>
> >     </table>
> >     </center></div>
> > </form>
> > </body>
> > </html>
> > ================= Start FormMail.jsp=====================
> >
> >
> > <html>
> >
> > <body bgcolor="white">
> >  <font size=5 color="black">
> >
> >  <%@ page import="javax.servlet.http.HttpUtils" %>
> >  <%@ page import="java.util.*" %>
> >  <%@ page import = "java.sql.*" %>
> >  <%@ page import = "java.io.*" %>
> >  <%@ page import= "sun.net.smtp.SmtpClient" %>
> >  <%
> >          String from,to,subject,msgbody,serverName;
> >          try
> >
> >
> >          from = request.getParameterValues("from")[0];
> >          to = request.getParameterValues("to")[0];
> >          subject = request.getParameterValues("subject")[0];
> >          msgbody = request.getParameterValues("msgbody")[0];
> >          serverName = request.getParameterValues("server")[0];
> >                  }
> >          catch (Exception e) // Generally Speaking, an
> Error getting one
> of
> > these
> >        // Values means that it wasnt passed in; inform the user
> >                  {
> >                  out.println("You must call this JSP from this ");
> >                  out.println("<A href=\"FormMail.html\">
> form</A>.<BR>");
> >                  out.flush();return;
> >                  }
> >  %>
> >
> >  Hold On A Moment while I try to Send Your Mail...  <BR>
> >
> >  <%
> >          out.flush();
> >          // Here are the real guts of the mail sending
> >          try
> >                  {
> >          sun.net.smtp.SmtpClient sm = new
> > sun.net.smtp.SmtpClient(serverName);
> >          sm.from(from);
> >          sm.to(to);
> >          PrintStream msg = sm.startMessage();
> >          msg.println("To: ");       // Note dont use + for
> Performance
> >          msg.println(to);
> >          msg.println("Subject: ");
> >          msg.println(subject);
> >          msg.println();
> >
> >          msg.println(msgbody);
> >          msg.println("==============");
> >          msg.print("Email sent from a user at IP ");
> >          msg.println(request.getRemoteHost());
> >          sm.closeServer();
> >          out.println("Your Mail Has Been Sent!");
> >                  }
> >          catch (Exception e)
> >                  {
> >                  out.println("The mail couldn't be sent,
> probably because
> > the mailhost wasnt set correctly.<BR> ");
> >                  out.println("The error message I am getting is: ");
> >                  out.println(e.getMessage());
> >                  }
> >  %>
> >      <BR>
> >  <BR>
> >  <A HREF="FormMail.html">Click here to send another!</
> >
> >
> >
> >
> > ***************************************************************
> > * R. Jarett Kulm           | For a man to acheive all that is *
> > * [EMAIL PROTECTED]      | demanded of him, he must regard  *
> > * Technical Analyst        | himself as better than he is.    *
> > * Oracle Internet Products |              -- Goethe           *
> > ***************************************************************
> >
> > ----- Original Message -----
> > From: Jacob Madsen
> > To: [EMAIL PROTECTED]
> > Sent: Friday, October 29, 1999 7:56 AM
> > Subject: Sending email from JSP
> >
> >
> > Hi all
> >
> > Anyone know of a free Java bean to send e-mail from a JSP site, like
> CDONTS
> > in ASP?
> >
> > Thanks in advance!
> >
> > Jacob
> >
> >
> ==============================================================
> =============
> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> > FAQs on JSP can be found at:
> >  http://java.sun.com/products/jsp/faq.html
> >  http://www.esperanto.org.nz/jsp/jspfaq.html
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to