Mail Send simple example-jsp file

Source: Internet
Author: User
Tags mail
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>




Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.