That's what I was saying in my messages about JSP and mail.
This has hardly anything to do with JSP (I'm not saying it's a bad solution,
it's just not real JSP) This is just plain servlets and HTML.
Let me explain what I expect from a JSP - mail solution.

The problem isn't the sending of the mail itself, there are lots of beans
available to do that. After all, the SMTP protocol isn't that complicated,
you could easily create this yourself.
There are 2 solutions from Sun: one in the sun... packages and javamail. So
I think you have plenty of choice in components to send a mail message.
The real problem is that in most cases you want to create dynamic messages.
Of course it's possible to use code like:
mailBody.print("Hello ");
mailBody.print( lastName );
mailBody.print(" ");
mailBody.print( firstName );
mailBody.println(",");
mailBody.print( "I'd like to tell you about ..." );

The only thing is that JSP was invented to get rid of all those print
statements. Otherwise we could just as well use plain servlets.
So what I want is a possibility to create my mailmessage with code like

Hello, <%=lastName%> <%=firstName%>,
I'd like....

With the servlet I showed a few days ago, this is possible. You just create
a JSP that creates the body of a mail message and the servlet makes a
URLConnection to that page to read it and send it to it's destination.

Geert 'Darling' Van Damme


> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Deniz Ers z
> Sent: maandag 8 mei 2000 17:36
> To: [EMAIL PROTECTED]
> Subject: JSP solution for sending mail...
>
>
> JavaMail bean...
> ------------------------------------------------------------------
> ----------
> ----
> package mail;
>
> import java.io.*;
> import java.util.*;
> import java.net.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import javax.mail.*;
> import javax.mail.internet.*;
>
> public class JavaMail{
>
>  private String SMTPHost = "SMTP.ug.bcc.bilkent.edu.tr";
>  String from, to, subject, text;
>
>  public void setFrom(String name){
>   from = name;
>  }
>  public void setTo(String name){
>   to = name;
>  }
>  public void setSubject(String name){
>   subject = name;
>  }
>
>  public void setText(String name){
>   text = name;
>  }
>
>  public String send() {
>
>   String error = "";
>
>   try{
>    Properties sysProps = System.getProperties();
>    sysProps.put("mail.smtp.host",SMTPHost);
>    Session session = Session.getInstance(sysProps,null);
>
>    MimeMessage message = new MimeMessage(session);
>
>    Address fromAddress = new InternetAddress(from);
>    message.setFrom(fromAddress);
>
>    Address[] toAddress = InternetAddress.parse(to);
>    message.setRecipients(Message.RecipientType.TO,toAddress);
>
>    message.setSubject(subject);
>
>    message.setText(text.toString());
>    Transport.send(message);
>   }
>   catch (AddressException e){
>     error = error + e.getClass() + e.getMessage() + "\n";
>   }
>   catch (SendFailedException e){
>     error = error + e.getClass() + e.getMessage() + "\n";
>   }
>   catch (MessagingException e){
>     error = error + e.getClass() + e.getMessage() + "\n";
>   }
>
>   return error;
>  }
> }
> ------------------------------------------------------------------
> ----------
> -----
> mail.html
> ------------------------------------------------------------------
> ----------
> ------
> <html>
>
> <head>
>     <title>carts</title>
> </head>
>
> <body bgcolor="white">
>
> <form type=POST action=mail.jsp>
> <TABLE>
> <TR><TD>From:</TD><TD><input type=text name=from></TD></TR>
> <TR><TD>To:</TD><TD><input type=text name=to></TD></TR>
> <TR><TD>Subject:</TD><TD><input type=text name=subject></TD></TR>
> <TR><TD>Text:</TD><TD><TEXTAREA cols=52 name = text rows=5
> wrap=virtual></TEXTAREA></TD></TR>
> </TABLE>
> <input type=submit value = "Submit">
> </FORM>
> </body>
> </html>
>
> ------------------------------------------------------------------
> ----------
> ------
> mail.jsp
> ------------------------------------------------------------------
> ----------
> ------
> <html>
>
> <jsp:useBean id="mail" scope="session" class="mail.JavaMail" />
>
> <jsp:setProperty name="mail" property="*" />
>
> <%@ include file ="/db/mail.html" %>
>
> <%
>  String error = mail.send();
>  if(error.equals(""))
> %>
> Successfull
> <%
>     else
> %>
>
> <%=error%>
>
> </TABLE>
>
> </html>
> ------------------------------------------------------------------
> ----------
> ------
>
> ==================================================================
> =========
> 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
>
>

===========================================================================
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