6 Replies Latest reply on Jul 23, 2012 11:26 PM by ohmygod

    How to configure a mail service in JBoss 7

    ohmygod

      In old jboss (version 4), there is a mail-service.xml to configure mail service like pop3 port and smtp port as following:

       

       

        <mbean code="org.jboss.mail.MailService"
               name="jboss:service=Mail">
          <attribute name="JNDIName">java:/Mail</attribute>
          <attribute name="User">nobody</attribute>
          <attribute name="Password">password</attribute>
          <attribute name="Configuration">
            <!-- A test configuration -->
            <configuration>
              <!-- Change to your mail server prototocol -->
              <property name="mail.store.protocol" value="pop3"/>
              <property name="mail.transport.protocol" value="smtp"/>
      
      
              <!-- Change to the user who will receive mail  -->
              <property name="mail.user" value="nobody"/>
      
      
              <!-- Change to the mail server  -->
              <property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/>
      
      
              <!-- Change to the SMTP gateway server -->
              <property name="mail.smtp.host" value="smtp.nosuchhost.nosuchdomain.com"/>
              
              <!-- The mail server port -->
              <property name="mail.smtp.port" value="25"/>
              
              <!-- Change to the address mail will be from  -->
              <property name="mail.from" value="nobody@nosuchhost.nosuchdomain.com"/>
      
      
              <!-- Enable debugging output from the javamail classes -->
              <property name="mail.debug" value="false"/>
            </configuration>
          </attribute>
          <depends>jboss:service=Naming</depends>
        </mbean>
      
      

       

      Currently I want to configure these attributes in JBoss 7.1.1.Final. I searched the documentation in JBoss as 7 but cannot find anything about this. And in standalone-full.xml I only found this piece of setting on mail.

       

      <subsystem xmlns="urn:jboss:domain:mail:1.0">
                  <mail-session jndi-name="java:jboss/mail/Default">
                      <smtp-server outbound-socket-binding-ref="mail-smtp"/>
                  </mail-session>
              </subsystem>
      
      

       

      Can someone tell me some more?

        • 1. Re: How to configure a mail service in JBoss 7
          ctomc

          Hi,

           

          configuration of mail subsystem is done more structured way rather than just providing bunch of properties that system cannot understand and manage.

           

          in any case i think this full blown example would help you out:

           

          <subsystem xmlns="urn:jboss:domain:mail:1.0">

              <mail-session jndi-name="java:/Mail" from="user dot name at domain dot tld">

                  <smtp-server outbound-socket-binding-ref="mail-smtp" ssl="true">

                      <login name="nobody" password="pass"/>

                  </smtp-server>

                  <pop3-server outbound-socket-binding-ref="mail-pop3"/>

                  <imap-server outbound-socket-binding-ref="mail-imap">

                      <login name="nobody" password="pass"/>

                  </imap-server>

              </mail-session>

              <mail-session debug="true" jndi-name="java:jboss/mail/Default">

                  <smtp-server outbound-socket-binding-ref="mail-smtp"/>

              </mail-session>

          </subsystem>

          in general you have to specify what kind of server are you configuring and outbound-socket-binding-ref, this are defined globaly at the end of configuration (just look for mail-smtp in standalone-full.xml)

          you can also set optional information about login info and/or server requres secure connection(ssl=true)

           

          hope this helps

           

          --

          tomaz

          • 2. Re: How to configure a mail service in JBoss 7
            ohmygod

            Thanks tomaz, I will have a try. Seems good

            • 3. Re: How to configure a mail service in JBoss 7
              ohmygod

              Hi tomaz, another question, how to configure an ssl protocal like, smtps? Or can you tell me all the optional attributes that can be configured?

              • 4. Re: How to configure a mail service in JBoss 7
                ctomc

                Hi,

                 

                simple just define smtp and specify ssl=true

                 

                <smtp-server outbound-socket-binding-ref="mail-smtp" ssl="true">

                       <login name="nobody" password="pass"/>

                </smtp-server>

                 

                --

                tomaz

                • 5. Re: How to configure a mail service in JBoss 7
                  ohmygod

                  Hi Tomaz, can you also provide some code sample for the new mail service configuration in JBoss 7?

                   

                  In older version JBoss, my code is like following. But I found in JBoss 7, using below code will report error like

                  10:33:56,019 ERROR [com.demo.util.mail.MailSender] (Thread-65 (HornetQ-client-global-threads-200946616)) Error getting email authentication parameters: 
                  com.demo.util.mail.MailerException: Mail -- service jboss.naming.context.java.Mail
                  

                   

                  After debugging, the real exception is

                   

                  javax.naming.NameNotFoundException: Mail -- service jboss.naming.context.java.Mail
                  

                   

                  Code:

                  Context initCtx = new InitialContext();
                  javax.mail.Session session = (Session) initCtx.lookup("java:/Mail");
                  
                  String transportProtocol = session.getProperty("mail.transport.protocol");
                  String mailServer = session.getProperty("mail.smtp.host");
                  String mailUser = session.getProperty("mail.smtp.user");
                  
                  
                  • 6. Re: How to configure a mail service in JBoss 7
                    ohmygod

                    Changging the jndi name to "java:jboss/mail/Default" makes it work. Thanks again for the advice.