Configuring mail sessions in tomcat

Solution Unverified - Updated -

Environment

  • JBoss Enterprise Web Server (EWS) 2.x
  • Tomcat 7.0.x

Issue

  • How can we configure java mail sessions in Tomcat?

Resolution

  • You can set up mail sessions in the global tomcat context.xml and web.xmls or application layer context/web.xml:
<Context>
<Resource name="mail/Session" auth="Container"
        type="javax.mail.Session"
        username="my.smtp.user"
        password="my-secret"
        mail.debug="false"
        mail.transport.protocol="smtp"
        mail.smtp.host= "xxx.xxx.xxx.xxx"
        mail.smtp.auth= "true"
        mail.smtp.port= "25"
        mail.smtp.starttls.enable="true"
        description="Global E-Mail Resource"
    />
</Context>

<web-app>
... 
<resource-ref>
        <description>Email Session</description>
        <res-ref-name>mail/Session</res-ref-name>
        <res-type>javax.mail.Session</res-type>
        <res-auth>Container</res-auth>
</resource-ref>
...
</web-app>

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.