Js
mailexample.jsp
<title>jsp JavaMail Example </title>
<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 ("to");
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 "So we can" what is going on
Passing false would not echo debug info, and passing true
Will.
Mailsession.setdebug (Sessiondebug);
Instantiate a new mimemessage and fill it with the
Required information.
Message msg = new MimeMessage (mailsession);
Msg.setfrom (New InternetAddress (from));
Internetaddress[] Address = {new internetaddress (to)};
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 is sent to" + to);
Out.println ("from" + from);
OUT.PRINTLN ("Using host" + Host + ".");
%>
</table>
</body>