JavaMail email is applied under JBoss3.0-Tomcat 4.03.

zhaozj2021-02-16  60

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

Archives = "mail.jar, activation.jar, mail-plugin.jar" />

Name = "jboss: service = mail">

Java: / Mail

NoBody

Password

I use www.21cn.com's free email, it is necessary to pass SMTP authentication, so it is necessary here.

Nobody password

Modified files are as follows

Archives = "mail.jar, activation.jar, mail-plugin.jar" />

Name = "jboss: service = mail">

Java: / Testjbossmail

lacklhl // username

Password // Password

If you want to pass SMTP authentication, you must have this kind of sentence.

is not available in JBoss, everyone must add.

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

Web.xml content is

"- // Sun Microsystems, Inc.//dtd Web Application 2.3 // En"

"http://java.sun.com/dtd/web-app_2_3.dtd">

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"%>

Test JBSSSMail DB

<%

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 ();

}

}

%>

from:

to:

Subject:

content: