- Platform and protocol-independent framework for building [email] messaging applications
Split into abstract API and protocol-specific SPI
- Default implementation for SMTP, POP3, IMAP
- Optional in J2SE, included in J2EE
- In J2EE, application server generally manage a mail session - a shared resource for sending email messages over SMTP
JavaMail implicitly uses JavaBeans Activation Framework (JAF).
JAF provides standard services to:
- determine the type of an arbitrary piece of data,
- encapsulate access to it,
- discover the operations available on it,
- and create the appropriate JavaBeans component to perform those operations
- JAF unifies the manner of working with various data formats, be it simple text files, or complex types such as audio, images, video, etc. JAF provides a framework for plugging in data-handlers into JavaMail.
-
Configured in JBoss AS by
deploy/mail-service.xml
Shared connection information for sending email messages over SMTP
Set
mail.smtp.host
indeploy/mail-service.xml
, and optionally setmail.debug
totrue
:<server> <mbean code="org.jboss.mail.MailService" name="jboss:service=Mail"> <attribute name="JNDIName">java:/Mail</attribute> ... <attribute name="Configuration"> <configuration> ... <property name="mail.smtp.host" value="smtp.nosuchhost.nosuchdomain.com"/> <property name="mail.smtp.port" value="25"/> ... </configuration> </attribute> ... </mbean> </server>
To enable support for SMTP over SSL:
<server> <mbean code="org.jboss.mail.MailService" name="jboss:service=Mail"> ... <attribute name="Configuration"> <configuration> ... <property name="mail.smtp.port" value="465"/> <property name="mail.smtp.ssl.enable" value="true"/> <property name="mail.smtp.socketFactory.class" value="javax.net.ssl.SSLSocketFactory"/> ... </configuration> </attribute> ... </mbean> </server>
To enable support for SMTP authentication:
<server> <mbean code="org.jboss.mail.MailService" name="jboss:service=Mail"> ... <attribute name="User">your-username</attribute> <attribute name="Password">your-password</attribute> <attribute name="Configuration"> <configuration> ... <property name="mail.smtp.auth" value="true"/> <property name="mail.smtp.user" value="your-username"/> ... </configuration> </attribute> ... </mbean> </server>
- Can also configure the defaults for receiving mail over POP/IMAP4
-
Can enable debugging to STDOUT
<property name="mail.debug" value="true"/>
![]() | Note |
---|---|
If you don’t have access to mail server that will relay your mail then set |
gmail.com. 2156 IN MX 5 gmail-smtp-in.l.google.com. gmail.com. 2156 IN MX 20 alt2.gmail-smtp-in.l.google.com. gmail.com. 2156 IN MX 10 alt1.gmail-smtp-in.l.google.com. gmail.com. 2156 IN MX 30 alt3.gmail-smtp-in.l.google.com. gmail.com. 2156 IN MX 40 alt4.gmail-smtp-in.l.google.com.
-
Configure
mail-service.xml
for your environment In
sendmail.war
- Determine the resource requirement
- Add required resource mapping
-
Deploy
sendmail.war
- Test that you can send email
- Experiment by enabling debugging
![]() | Note |
---|---|
SMTP authentication for JavaMail under JBoss is not trivial to enable. Experiment without it. Try setting the mail server to the host that handles your own email. |