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 + ".");
%>