Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_jsp thread: how to send an e-mail from jsp


Message #1 by "kumar Tatimatla" <kumar_tatimatla@h...> on Sat, 1 Jul 2000 11:20:19
Of course it's possible to use javamail to send an email from JSP.
However, even when using javamail, emailing from JSP still isn't obvious.
As I see it, it would be nice to have the possibility of not only sending 
the emails from JSP, but also to create the body of the message in a JSP 
style. The body text shouldn't be written to the normal 'out' but to a 
PrintStream that writes to the mail message you created.
If you end up writing code in between <% %> with lot's of 
mailout.println("blablabla ") statements and you're not really doing JSP. 
That's a plain servlet ;-)

It would be very nice if you could use a JSP approach to sending email.
There are some possibilities to do this.
- I know there are a few tag libraries that have this kind of email 
support.
- You could try to fool the servlet by temporarily redirecting the 'out' 
parameter to the PrintStream that writes the email message  (and I think 
this is how the custom tags do it). But IMO that's no clean code. I didn't 
try this yet, and it might work well. Has anyone tried this approach yet?
- The solution I once used is to write a servlet that opens a 
httpConection, reads the page and sends this to the specified address. If 
you're interested, I can post the code.
That way you can write a JSP page that represents the message of the email, 
you can view the email you're going to send in your browser and to send it, 
you just include a call to the servlet with the appropriate parameters 
like
http://www.yourserver.com/servlet/MailPage?from=geert.vandamme@d...&to=theaddress@s...&source=http://www.gojasper.be&sub
ject=test

See what I mean?

Geert Van Damme


  Return to Index