Smtpclient class sends simple text emails

Source: Internet
Author: User
Tags smtpclient

Use the smtpclient class to send simple text emails, but cannot send emails containing attachments.
To a receiver, it is a built-in JDK package, so it is more universal.
The javamail package provides excellent functions to write any powerful email.
System.

Source code.
<% --
Function: JSP routine. use JSP to send an email.

%>
<% @ Page contenttype = "text/html; GBK" %>
<% @ Page import = "sun.net. SMTP. smtpclient" %>
<HTML>
<Head>
<Title>
Send email
</Title>
</Head>
<Body>
<Form method = "Post" Action = "sendmail. jsp">
Recipient address: <input type = "text" name = "to">
Sender address: <input type = "text" name = "from">
Subject: <input type = "text" name = "server" value = "smtp.163.com">
Letter content: <textarea name = "content" Cols = "73" rows = "5"> </textarea>
<Input type = "Submit" value = "send">
</Form>
Enter required options
<Br>

<%
// Obtain parameters
String to = request. getparameter ("");
String from = request. getparameter ("from ");
String subject = request. getparameter ("subject ");
String Server = request. getparameter ("server ");
String content = request. getparameter ("content ");
// If the parameters are obtained and the conditions are met, enter the mail program segment
If (! To. Equals ("")&&! From. Equals ("")&&! Subject. Equals ("")&&! Server. Equals (""))
{
Tyr {
Smtpclient mail = new smtpclient (server );
Mail. From (from );
Mail. To ();
Java. Io. printstream mailout =
Mail. startmessage ();
Mailout. println ("from:" + from );
Mailout. println ("to:" + );
Mailout. println ("Subject:" + subject );
Mailout. println (content );
Mailout. Print ("/R/N ");
Mailout. Flush ();
Mail. closeserver ();
Out. println ("sent successfully, you can send the next letter ");
}
Catch (exception e ){
Out. println ("error:" + E. tostring ());
}
}

%>
</Body>
</Html>

 

 

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.