Operator System: Windows 2000 Server 2
Application Server: JBoss3.0-Tomcat4.03
DB: Oracle8.17
JDK: JDK1.31
Web Server apache1.3
First install JBoss3.0-Tomcat4.03 I installed in E: /JBOSS3.0_TOMCAT4.03, open the mail-service.xml under the E: /JBOSS3.0_TOMCAT4.03/server/default/deploy's directory, the contents of the contents are as follows
XML Version = "1.0" encoding = "UTF-8"?>
Archives = "mail.jar, activation.jar, mail-plugin.jar" /> Name = "jboss: service = mail"> configure> attribute> mbean> server> I use www.21cn.com's free email, it is necessary to pass SMTP authentication, so it is necessary here. Modified files are as follows XML Version = "1.0" encoding = "UTF-8"?> Archives = "mail.jar, activation.jar, mail-plugin.jar" /> Name = "jboss: service = mail"> configure> attribute> mbean> server> If you want to pass SMTP authentication, you must have this kind of sentence. In fact, everyone can modify according to their needs, in fact, SMTP certified Java code is like this. protected session getsession () { Session MailSession = NULL; IF (! getpassword (). Equals ("") &&! getuser (). Equals ("")) { Final PasswordAuthentication Pa = New PasswordAuthentication (getuser (), getpassword ()); Authenticator a = new authenticator () { Protected passwordautAuthentication getPasswordAuthentication () { Return Pa; } } Properties PROPS = getProperties (); Mailsession = session.getInstance (PrOPS, A); } else { Properties PROPS = getProperties (); Mailsession = session.getInstance (PrOPS, NULL); } Return Mailsession; } Below I will write a simple Sendmail test, and if you collect the email, (I use JSP, in sessionbean, Javabean is basically the same), write .war or .ear bag to test a simple The practice is: 1. Establish a Sendmail-Test.war directory in a deploy directory. 2. Create a web-inflicity in the sendmail-test.war directory, two files JBoss-web.xml and web.xml The content is JBoss-web.xml content is jboss-web> Web.xml content is XML Version = "1.0"?>
"- // Sun Microsystems, Inc.//dtd Web Application 2.3 // En" "http://java.sun.com/dtd/web-app_2_3.dtd"> web-app> Third, establish a new file in the sendmail-test.war directory Index.jsp whose content is <% @ Page ContentType = "Text / HTML"%> <% @ page import = "javax.mail. *, javax.mail.internet. *, javax.activation. *, javax.naming.initialcontext"%> <% String toaddress = Request.getParameter ("mailto"); String fromaddress = Request.GetParameter ("mailfrom"); String Subject = Request.getParameter ("mailsubject"); String content = Request.getParameter ("mailcontent"); InitialContext CTX = new initialContext (); Session sessions = (session) CTX.lookup ("java: / testjbossmail"); IF (toaddress! = null&&&! toaddress.equals (")) { Try { MIMEMESSAGE MSG = New MimeMessage (sessions); Msg.SetFrom (New InternetDress (fromaddress); Msg.SetRecipients (javax.mail.Message.RecipientType.to, toaddress); Msg.setsubject (Subject); Msg.setsentdate (New java.util.date ()); Multipart multipt = new mimemultipart (); MIMEBODYPART MSGBODY = new mimebodypart (); Msgbody.setContent (Content, "Text / Plain"); Multipt.addbodypart (msgbody); Msg.setContent (MULTIPT); Transport.send (MSG); System.out.println ("Sendmail OK!"); } Catch (MessagingException E) { E.PrintStackTrace (); } } %> TR> TR> Test JBSSSMail DB h3>
td>
td>