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

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

First, any support we can regulate the sun.net.smtp 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 http://java.sun.com/products/javamail/. Although the API than sun.net.smtp.SmtpClient 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 (\ "mail.smtp.host \", 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);

)

)
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

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

  • J2EE Architect road

    J2EE Architect road Looking casual, working into the fifth year, the discovery came from the Java programmer to architect J2EE course. Found that computer to install a wide range of J2EE tools: JBuilder, WSAD, Eclipse, Rose, Together, Weblogic, Jtest, Opt

  • RoR explained

    ROR is Ruby on Rails. Ruby is a well-known has been very good dynamic language It's dynamic language. Simple and easy. Dynamic languages are interpreted, but the performance may make a discount, but not absolute, because the application is complex, th

  • spring myfaces hibernate richfaces

    1.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j

  • Some interview questions java

    The first is the company give you a chance to meet, it is necessary to know to meet from time to equal the interview, and have a lot of companies to see you at the first time will give you a ready point of doing something trivial, these questions, althoug

  • Spring + Hibernate to use Glassfish Database Connection Pool

    applicationContext.xml file content <? xml version = "1.0" encoding = "UTF-8"?> <beans xmlns = " http://www.springframework.org/schema/beans " xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance " ...

  • Process migration from tomcat to websphere changes

    Process migration from tomcat to websphere changes Because customers use the web application server software used by different what tomcat5, tomcat6, websphere5.1, websphere6.1, weblogic8, and so on, and the software used inconsistent standards, ibm's

  • JAVA EE JSP_JNDI

    dsfdsa http://lindows.javaeye.com/admin/blogs/213348 Tomcat 6 with the connection pool data source configuration http://www.blogjava.net/ec2008/archive/2008/07/19/216063.html project: test Driver path: D: \ workspace \ test \ WebRoot \ WEB-INF \ lib ...

  • The EJB3 Persistence

    EJB3 persistence with Hibernate is very similar to the mechanism: Environment: Server: JBOSS5.0 Database: MySQL5.0 1. Set up a data source First of all, in jboss-5.0.0.GA \ server \ default \ deploy, the establishment of a database used to connect the dat

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • Great collection of java interview topics

    1, object-oriented features of what has 1. Abstract: Abstract is that it has overlooked a subject has nothing to do with the current goal of those aspects in order to more fully with the current objectives of the attention-related aspects. Abstract does n

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries