1 Reply Latest reply on Dec 29, 2005 10:03 AM by Eugene Onischenko

    sending a mail from a bean

    Rodrigo lopes Newbie

      I'm developing an application using EJB 3.0 on JBoss 4.0.3. I would like some hints on how to send e-mails from inside a bean, configure and use the jboss mail API implementation.

      thanks

        • 1. Re: sending a mail from a bean
          Eugene Onischenko Newbie

          You can configure mail service by editing mail-service.xml file in your deploy directory.

          Sample code:

          import javax.mail.Transport;
          import javax.mail.Session;
          import javax.ejb.SessionContext;
          
          @Stateless
          public class SessionBean implements ISessionBeanLocal{
           @Resource(mappedName="java:/Mail")
           private Session mailSession;
          
           @Resource
           private SessionContext ctx;
          
           public void sendAMessage(){
           MimeMessage m = new MimeMessage(session);
           m.setFrom(fromAddress);
           ............
           Transport.send(m)
           }
          
           public void legacySend(){
           Session mailSession = (Session)PortableRemoteObject.narrow(
           ctx.lookup("java:/Mail"), Session.class);
           MimeMessage m = new MimeMessage(session);
           m.setFrom(fromAddress);
           ............
           Transport.send(m)
           }
          }