Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

16.2. Receiving emails

If you are using EJB then you can use a MDB (Message Driven Bean) to receive email. Seam comes with an improved version of mail-ra.rar as distributed in JBoss AS; until the improvements make there way into a released version of JBoss AS, replacing the default rar with the one distributed with Seam is recommended.
You can configure it like this:
@MessageDriven(activationConfig={
         @ActivationConfigProperty(propertyName="mailServer", propertyValue="localhost"),
         @ActivationConfigProperty(propertyName="mailFolder", propertyValue="INBOX"),
         @ActivationConfigProperty(propertyName="storeProtocol", propertyValue="pop3"),
         @ActivationConfigProperty(propertyName="userName", propertyValue="seam"),
         @ActivationConfigProperty(propertyName="password", propertyValue="seam")
})
@ResourceAdapter("mail-ra.rar")
@Name("mailListener")
public class MailListenerMDB implements MailListener {

   @In(create=true)
   private OrderProcessor orderProcessor;

   public void onMessage(Message message) {
      // Process the message
      orderProcessor.process(message.getSubject());
   }
   
}
Each message received will cause onMessage(Message message) to be called. Most seam annotations will work inside a MDB but you musn't access the persistence context.
You can find more information on the default mail-ra.rar at https://wiki.jboss.org/wiki/Wiki.jsp?page=InboundJavaMail. The version distributed with Seam also includes a debug property to enable JavaMail debugging, a flush property (by default true) to disable flushing a POP3 mailbox after successfullying delivering a message to your MDB and a port property to override the default TCP port. Beware that the api for this may be altered as changes make there way into JBoss AS.
If you aren't using JBoss AS you can still use mail-ra.rar (included with Seam in the mail directory), or you may find your application server includes a similar adapter.

 
 
  Published under the terms of the Open Publication License Design by Interspire