Javamail called in jsp

Source: Internet
Author: User

Javamail calls
<HTML>
<BODY>
<FORM action = "sendmail. jsp (preferred for SUN Enterprise Applications)" method = "post">
<TABLE align = "center">
<TR>
& Lt; TD width = "50%" & gt;
To: <BR> <INPUT name = "to" size = "25">
</TD>
& Lt; TD width = "50%" & gt;
From: <BR> <INPUT name = "from" size = "25">
</TD>
</TR>
<TR>
<TD colspan = "2">
Subject: <BR> <INPUT name = "subject" size = "50">
</TD>
</TR>
<TR>
<TD colspan = "2">
<P> Message: <BR> <TEXTAREA name = "text" rows = 25 cols = 85> </TEXTAREA> </P>
</TD>
</TR>
</TABLE>
<INPUT type = "submit" name = "cb_submit" value = "Send">
<INPUT type = "reset" name = "cb_reset" value = "Clear">
</FORM>
</BODY>
</HTML>

Javamail calls 2 in jsp (the preferred choice for SUN Enterprise applications)
<% @ Page
Import = "javax. mail. *, javax. mail. internet. *, javax. activation. *, java. util .*"
%>
<Html>
<Head>
<TITLE> jsp (preferred for SUN Enterprise Applications) meets JavaMail, what a sweet combo. </TITLE>
</HEAD>
<BODY>
<%

Try {
Properties props = new Properties ();
Session sendMailSession;
Store store;
Transport transport;


SendMailSession = Session. getInstance (props, null );

Props. put ("mail. smtp. host", "smtp. jsp (preferred for SUN Enterprise Applications) insider.com ");

Message newMessage = new MimeMessage (sendMailSession );
NewMessage. setFrom (new InternetAddress (request. getParameter ("from ")));
NewMessage. setRecipient (Message. RecipientType. TO, new InternetAddress (request. getParameter ("")));
NewMessage. setSubject (request. getParameter ("subject "));
NewMessage. setSentDate (new Date ());
NewMessage. setText (request. getParameter ("text "));

Transport = sendMailSession. getTransport ("smtp ");
Transport. send (newMessage );
%>
<P> Your mail has been sent. </P>
<%
}
Catch (MessagingException m)
{
Out. println (m. toString ());
}
%>
</BODY>
</HTML>

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.