In the jsp (SUN enterprise applications preferred) to send email

In the jsp (SUN enterprise applications preferred) to send email

First, any support we can regulate the sun package jsp (SUN enterprise application of choice) engine (such as JSWDK) to send mail.

(Warning: Use the built-in internal Sun specification package, which will affect your jsp (SUN enterprise application of choice) program portability.)

The following scriptlet using SmtpClient class in jsp (SUN enterprise application of choice) file to send email.

Second, JavaMail is the official Java mail API, refer to Although the API than richer or more complex, but it is portable. Here re-creates a MailSender class, which contains the JavaMail API. As follows:

/ / Ms_ prefix is for MailSender class variables

/ / Str prefix is for String

/ / Astr prefix is for array of Strings

/ / Strbuf prefix is for StringBuffers, etc.

public MailSender (

String strFrom, / / sender

String [] astrTo, / / recipient (s)

String [] astrBCC, / / bcc recipient (s), optional

String strSubject, / / subject

boolean debugging)


ms_strFrom = strFrom; / / who the message is from

ms_astrTo = astrTo; / / who (plural) the message is to

ms_debugging = debugging; / / who (plural) the message is to

/ / Set the host

Properties props = new Properties ();

props.put (\ " \", ms_strSMTPHost);

/ / Create some properties and get the default Session

Session session = Session.getDefaultInstance (props, null);

session.setDebug (ms_debugging);

try (

/ / Create a message

ms_msg = new MimeMessage (session);

/ / Set the from

InternetAddress from = new InternetAddress (strFrom);

ms_msg.setFrom (from);

/ / Set the to

InternetAddress [] address = new InternetAddress [astrTo.length];

for (int i = 0; i astrTo.length; + + i)


address [i] = new InternetAddress (astrTo [i]);


ms_msg.setRecipients (Message.RecipientType.TO, address);

/ / Set the bcc recipients

if (astrBCC! = null)


address = new InternetAddress [astrBCC.length];

for (int i = 0; i astrBCC.length; + + i)


eh.dbg (\ "astrBCC [\" + i + \ "] is: \ '\" + astrBCC [i] + \ "\' \");

address [i] = new InternetAddress (astrBCC [i]);


ms_msg.setRecipients (Message.RecipientType.BCC, address);


/ / Set the subject

ms_msg.setSubject (strSubject);

/ / Set up the string buffer which will hold the message

ms_strbufMsg = new StringBuffer ();

) Catch (MessagingException mex) (

mex.printStackTrace (System.err);

) Catch (Exception ex) (

ex.printStackTrace (System.err);



public void ms_add (String strText)


ms_strbufMsg.append (strText);


public void ms_send ()


try (

/ / Set the content as plain text

ms_msg.setContent (new String (ms_strbufMsg), \ "text / plain \");

/ / And away

Transport.send (ms_msg);

) Catch (Exception ex) (

System.out.println (\ "Caught exception in MailSender.ms_send: \" + ex);



分类:Java 时间:2010-07-12 人气:177
blog comments powered by Disqus


  • <% @ Taglib uri = "" prefix = "c"%> does not recognize the error: to htt 2008-08-28

    <% @ Taglib uri = "" prefix = "c"%> does not recognize the error: To https: / / / download.html to download jstl of the two on the jar package. Import project can be

  • In the JSP in This absolute uri cannot be resolved - the solution 2010-08-28

    About JSP in org.apache.jasper.JasperException: This absolute uri cannot be resolved in either web.xml or the jar files deployed with this application According "master JSP - Web application development technology a

  • About org.apache.jasper.JasperException: The absolute uri: 2009-05-24

    This problem usually occurs because the jar (jstl.jar, and standard.jar) caused problems: The first is: Eclipse project is to import JSTL.jar and standard.jar Second: Modify the web.xml, add the following statement: <jsp-config> <taglib> <t

  • Use Java Service Wrapper to Java program as Windows system service 2010-07-09

    Transfer from: In many cases Java program is run as a service, in Un * x platforms can be added using the command "&" the program runs as a background service,

  • jsp java mai Send e-mail format 2010-09-23

    JavaMail send mail two basic jar: Annex 1, mail.jar Annex 2, activation.jar Annex 3, to read jsp or html class is divided into two one, send html format two page JavaMail.jsp welcome. jsp, a welcome.jsp the source file to load into a S

  • JSP (JAVA) B2C software SHOP + + core technology 2010-09-22

    1. Programming Language SHOP + + programming language design based on JAVA, JAVA is a cross-platform, object-oriented programming language, which main advantage is reflected in simple, object-oriented, distributed, explanatory, robust, secure, platfo

  • Sun CEO称Java软件商店潜在用户可达10亿 2014-06-12

    新浪科技讯 北京时间5月22日上午消息,据国外媒体报道,Sun CEO乔纳森·施瓦茨(Jonathan Schwartz)表示,该公司将推Java软件商店,潜在用户可达10亿. 目前,Sun的Java软件商店代号为"Project Vector","Java Store"可能成为其正式名称.施瓦茨称Java软件商店是一款"网络服务",将把各种类型和规模的公司与全球约10亿Java用户"联系在一起".施瓦茨周一在一篇博客文章中称

  • Java language coding standards (Java Code Conventions 2009-01-05

    At the beginning of Notes ") - Package and the introduction of statements (see "package and the introduction of statements") - Class and interface declarations (see "classes and int

  • Reprinted: from Java to C + + - Comparison Java and C + + programming different 2010-02-19

    Transfer from: Original: Cay Horstmann English text Translation: Aqua Note: Many programmers, including myself is to learn the Java, and knowledge, the C + +, in fact C + + and Java there are many similariti

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 黔ICP备15002463号-1

processed in 0.645 (s). 12 q(s)