MailExample. jsp
<Html>
<Head>
<Title> JSP JavaMail Example </title>
</Head>
<Body>
<% @ Page import = "java. util. *" %>
<% @ Page import = "javax. mail. *" %>
<% @ Page import = "javax. mail. internet. *" %>
<% @ Page import = "javax. activation. *" %>
<%
String host = "yourmailhost ";
String to = request. getParameter ("");
String from = request. getParameter ("from ");
String subject = request. getParameter ("subject ");
String messageText = request. getParameter ("body ");
Boolean sessionDebug = false;
// Create some properties and get the default Session.
Properties props = System. getProperties ();
Props. put ("mail. host", host );
Props. put ("mail. transport. protocol", "smtp ");
Session mailSession = Session. getDefaultInstance (props, null );
// Set debug on the Session so we can see what is going on
// Passing false will not echo debug info, and passing true
// Will.
MailSession. setDebug (sessionDebug );
// Instantiate a new MimeMessage and fill it with
// Required information.
Message msg = new MimeMessage (mailSession );
Msg. setFrom (new InternetAddress (from ));
InternetAddress [] address = {new InternetAddress ()};
Msg. setRecipients (Message. RecipientType. TO, address );
Msg. setSubject (subject );
Msg. setSentDate (new Date ());
Msg. setText (messageText );
// Hand the message to the default transport service
// For delivery.
Transport. send (msg );
Out. println ("Mail was sent to" + );
Out. println ("from" + from );
Out. println ("using host" + host + ".");
%>
</Table>
</Body>
</Html>