1. A lot of email from the client, the actual application of the actual value of the small, real life is the most used in the Web page to send email function, here, such as a Web application with the mail delivery function.
2. The following is an example of a Web email using Comcast with its own jndi and its analysis:
Package com.web.servlet;
Import java.io.IOException;
Import Javax.mail.Message;
Import javax.mail.Session;
Import Javax.mail.Transport;
Import javax.mail.internet.InternetAddress;
Import Javax.mail.internet.MimeMessage;
Import Javax.naming.Context;
Import Javax.naming.InitialContext;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse; /** * Use a content.xml configuration file to write a Web email */public class Sendmailservlet extends HttpServlet {public void doget (httpse Rvletrequest request, HttpServletResponse response) throws Servletexception, IOException {try {context Contex
T = (context) new InitialContext (). Lookup ("java:comp/env");
Session Sessions = (session) context.lookup ("Mail/context");
msg = new MimeMessage (session);
Msg.setfrom (New InternetAddress ("itcast_test@sina.com")); Internetaddress[] to = {new InternetAddress ("itcast_test@sina.com")};
Msg.setrecipients (message.recipienttype.to,to);
Msg.setsubject ("web email");
Msg.settext ("This is a Java Web written email");
Transport transport = Session.gettransport ();
Transport.connect ("Itcast_test", "123456");
Transport.sendmessage (msg,to);
Transport.close ();
Response.getwriter (). println ("Send ok!");
catch (Exception e) {e.printstacktrace (Response.getwriter ()); } public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, Ioexce
ption {doget (request, response); } The resources defined in this elements may is referenced by the following elements in the Web application Deploymen T Descriptor (/web-inf/web.xml) of the Your WEB application; Important profile Context.xml, the file is placed under Web-inf Meta-inf, which is detailed below: < context> <resource name= "Mail/context" auth= "Container" type= "Javax.mail.Session" mail.smt P.host= "smtp.sina.com" mail.smtp.auth= "true" MAIL.TRANSPort.protocol= "SMTP"/> </Context>