File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Sending email with content from web page & database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Sending email with content from web page & database" Watch "Sending email with content from web page & database" New topic
Author

Sending email with content from web page & database

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi, this one shouldn't be too bad...
Using JSP (or a servlet), how would I send (submit) an email to someone with content that originates on a web page (input)?
And how could I send an email with content from a database?
It's the actual sending of the email I'm not sure about, and the loading of its content.
I know how to get the data into the database (JDBC). FYI, I'm using Tomcat and a MySQL database. Thanks.
Cheers,
Scott
David Freels
Ranch Hand

Joined: Feb 01, 2001
Posts: 102
Check out javamail at http://www.javasoft.com/products/javamail
David
Sun Certified Programmer for the Java2 Platform
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
There are three easy ways:
1. SMTP using Sockets
Open a socket to your mail host and SMTP port number. If your ISP is foo.com, the mail host is usually mail.foo.com or something close. The port number is 25 by default. You can test this with telnet:

If this works, send these lines as ordinary text:

You'll get a response line after each of these. The return code is numeric and is contained in the first three bytes.
Obviously, I'm simplifying it a little. See RFC 821 (Simple Mail Transfer Protocol) for complete details at http://www.freesoft.org/CIE/RFC/821/index.htm .
2. Use the sun.net.smtp.SmtpClient class
This is marginally simpler, being an object-oriented wrapper around the bare socket protocol. There are two big drawbacks:
- It is undocumented (although not hard to figure out)
- Sun warns you that they can change or drop the class
3. Use JavaMail as previously noted.
Why bother with options 1 or 2 if option 3 is the preferred choice? Because it isn't difficult and it's worth learning what goes on under the covers. For a production mail system, obviously, you need the industrial strength option, but for simple applications, the socket-based approach may be all you need.
(This material is discussed at greater length in Chapter 21).
------------------
Phil Hanna
Author of :
JSP: The Complete Reference
Instant Java Servlets
[This message has been edited by Phil Hanna (edited April 24, 2001).]
[This message has been edited by Phil Hanna (edited April 24, 2001).]


Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks Phil!
Maybe I'll have to add your book to my collection
Cheers,
Scott
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending email with content from web page & database