3 Replies Latest reply on May 22, 2005 5:24 PM by javierdajabon

    How to Send an Email from a Java App in JBoss

    mduffy_lists

      Can anyone tell me how to configure the resource params for a mail server?

        • 1. Re: How to Send an Email from a Java App in JBoss
          javierdajabon

          Here is what my configuration file looks like. I think the only thing I had to change to make it work was to specify my company's smtp server name. I am not sure if you could do just that too, that is, I don't know if you may need to specify a valid user name/password as well.

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE server>
          <!-- $Id: mail-service.xml,v 1.4 2002/06/01 02:06:46 starksm Exp $ -->
          <server>
           <classpath codebase="lib" archives="mail.jar, activation.jar, mail-plugin.jar"/>
           <!-- ==================================================================== -->
           <!-- Mail Connection Factory -->
           <!-- ==================================================================== -->
           <mbean code="org.jboss.mail.MailService" name="jboss:service=Mail">
           <attribute name="JNDIName">java:/MailService</attribute>
           <attribute name="User">value</attribute>
           <attribute name="Password">value</attribute>
           <attribute name="Configuration">
           <!-- Test -->
           <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="yoursmtpserver.com"/>
           <!-- Change to the address mail will be from -->
           <property name="mail.from" value="JBossMailService"/>
           <!-- Enable debugging output from the javamail classes -->
           <property name="mail.debug" value="false"/>
           </configuration>
           </attribute>
           </mbean>
          </server>
          


          Hope this helps
          Javier

          • 2. Re: How to Send an Email from a Java App in JBoss
            mduffy_lists

            Thx.

            Were there any parameters that needed to be set in the web.xml?

            Mike

            • 3. Re: How to Send an Email from a Java App in JBoss
              javierdajabon

              Mike,
              Actually in my case I am not sending email from a web application so I do not have a web.xml. I created a simple Message Driven Bean which is listening to a queue. Each entry that arrives in this queue is an email that needs to be sent. In my MDB I just do a JNDI lookup to get a reference to the mail session and then send the email. You could basically send email in a similar manner as I am doing it by just deploying the mail-service.xml file and then doing lookups from a servlet or a helper class. You could do that even without having to declare anything in your web.xml. In case you need it, here is some sample code.

              Session mailSession = (Session)jndiContext.lookup("java:/MailService");
              MimeMessage mimeMessage = new MimeMessage(mailSession);
              mimeMessage.setFrom();
              etc..
              
              


              Given the mail-service.xml I posted earlier, MailService would be bound to JNDI and it will return a session to you when you do a look up.

              Javier