0 Replies Latest reply on May 21, 2008 1:55 PM by rogerwbmd

    Mail Receiver

    rogerwbmd

      I am new to Jboss and trying to write an email receiver by following http://wiki.jboss.org/wiki/InboundJavaMail. I created a new EJB3 MDB and put the sample code in it. It seems nothing happen after that. Is there anything I need to do, such as update the component.xml, to make it work.

      Environment:
      JBoss Developer Studio
      jboss-4.2.2.GA

      Code:

      package org.domain.OpsAI.mdb;
      
      import javax.ejb.ActivationConfigProperty;
      import javax.ejb.MessageDriven;
      import javax.mail.Message;
      import javax.mail.MessagingException;
      
      import org.jboss.annotation.ejb.ResourceAdapter;
      import org.jboss.resource.adapter.mail.inflow.MailListener;
      import org.jboss.logging.Logger;
      import org.jboss.seam.annotations.Name;
      
      
      /**
       * A JavaMail based MDB for EJB3 use
       */
      @MessageDriven(activationConfig={
       @ActivationConfigProperty(propertyName="mailServer", propertyValue="xx.xx.xx.xx"),
       @ActivationConfigProperty(propertyName="mailFolder", propertyValue="INBOX"),
       @ActivationConfigProperty(propertyName="storeProtocol", propertyValue="imap"),
       @ActivationConfigProperty(propertyName="userName", propertyValue="xxx"),
       @ActivationConfigProperty(propertyName="password", propertyValue="xxx")
      })
      @ResourceAdapter("mail-ra.rar")
      @Name("OpsaiMailListener")
      public class OpsaiMailListener implements MailListener
      {
       private static Logger log = Logger.getLogger(OpsaiMailListener.class);
      
       public void onMessage(Message msg)
       {
       try{
       log.info("onMessage, msg="+msg);
       System.out.println("got it"+msg.getSubject());
       }catch(MessagingException me){
       me.printStackTrace();
       }
       }
      }
      


      I also put the following in component.xml - I am not sure if it is necessary
      <mail:mail-session session-jndi-name="java:/Mail"/>


      And the mail-service.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!-- $Id: mail-service.xml 62349 2007-04-15 16:48:15Z dimitris@jboss.org $ -->
      <server>
      
       <!-- ==================================================================== -->
       <!-- Mail Connection Factory -->
       <!-- ==================================================================== -->
      
       <mbean code="org.jboss.mail.MailService"
       name="jboss:service=Mail">
       <attribute name="JNDIName">java:/Mail</attribute>
       <attribute name="User">xxx</attribute>
       <attribute name="Password">xxx</attribute>
       <attribute name="Configuration">
       <!-- A test configuration -->
       <configuration>
       <!-- Change to your mail server prototocol -->
       <property name="mail.store.protocol" value="imap"/>
       <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.imap.host" value="xx.xx.xx.xx"/>
      
       <!-- Change to the SMTP gateway server -->
       <property name="mail.smtp.host" value="xx.xx.net"/>
      
       <!-- The mail server port -->
       <property name="mail.smtp.port" value="25"/>
      
       <!-- Change to the address mail will be from -->
       <property name="mail.from" value="cms@qa.pol.net"/>
      
       <!-- Enable debugging output from the javamail classes -->
       <property name="mail.debug" value="true"/>
       </configuration>
       </attribute>
       <depends>jboss:service=Naming</depends>
       </mbean>
      </server>
      


      And I got the log after I made the mail-service.xml change
      13:50:22,963 INFO [MailService] Mail service 'java:/Mail' removed from JNDI
      13:50:22,978 INFO [STDOUT] DEBUG: JavaMail version 1.4ea
      13:50:22,978 INFO [STDOUT] DEBUG: java.io.FileNotFoundException: C:\Dev\Java\jdk1.5.0_15\jre\lib\javamail.providers (The system cannot find the file specified)
      13:50:22,978 INFO [STDOUT] DEBUG: !anyLoaded
      13:50:22,978 INFO [STDOUT] DEBUG: not loading resource: /META-INF/javamail.providers
      13:50:22,978 INFO [STDOUT] DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
      13:50:22,978 INFO [STDOUT] DEBUG: Tables of loaded providers
      13:50:22,978 INFO [STDOUT] DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
      13:50:22,978 INFO [STDOUT] DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
      13:50:22,978 INFO [STDOUT] DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
      13:50:22,978 INFO [STDOUT] DEBUG: !anyLoaded
      13:50:22,978 INFO [STDOUT] DEBUG: not loading resource: /META-INF/javamail.address.map
      13:50:22,978 INFO [STDOUT] DEBUG: java.io.FileNotFoundException: C:\Dev\Java\jdk1.5.0_15\jre\lib\javamail.address.map (The system cannot find the file specified)
      13:50:22,994 INFO [MailService] Mail Service bound to java:/Mail
      


      Any input is appreciated

      Thanks
      Roger