Author/Source: Blueski compilation (including two articles. The previous article uses sun.net. smtp, and the last one uses javamail.
1. We can send mail via any JSP Engine (such as JSWDK) that supports sun.net. smtp packages in sun specifications.
(Warning: using the built-in internal Sun specification package will affect the portability of Your jsp program .)
The following scriptlet uses the SmtpClient class to send emails to jsp files.
<% @ Page import = "sun.net. smtp. SmtpClient, java. io. *" %>
<%
String from = "gseshadri@hotmail.com ";
String to = "govind@jguru.com, govi@bigfoot.com ";
Try {
SmtpClient client = new SmtpClient ("mail. xxxxx. xxx ");
Client. from (from );
Client. to ();
PrintStream message = client. startMessage ();
Message. println ("To:" + );
Message. println ("Subject: Sending email from JSP! ");
Message. println ("This was sent from a JSP page! ");
Message. println ();
Message. println ("Cool beans! :-)");
Message. println ();
Message. println ("Govind Seshadri ");
Message. println ("jGuru.com ");
Message. println ();
Client. closeServer ();
}
Catch (IOException e ){
System. out. println ("error sending email:" + e );
}
%>
2. JavaMail is the official Java mail API. For details, refer to http://java.sun.com/products/javamail /. Although this API is richer or more complex than sun.net. smtp. SmtpClient, it is portable. Here, a new MailSender class is created, which contains the JavaMail API. As follows:
// Ms _ prefix is for MailSender class variables
// Str prefix is for String
// Astr prefix is for array of Strings
// Strbuf prefix is for StringBuffers, etc.
Public MailSender (
String strFrom, // sender
String [] astrTo, // recipient (s)
String [] astrBCC, // bcc recipient (s), optional
String strSubject, // subject
Boolean debugging)
{
Ms_strFrom = strFrom; // who the message is from
Ms_astrTo = astrTo; // who (plural) the message is
Ms_debugging = debugging; // who (plural) the message is
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.