0 Replies Latest reply on Sep 22, 2015 8:25 AM by nansjames

    Jboss 7 configuration with apache james 2.3 to send mail to external mail server like gmail,yahoo...

    nansjames

      I am trying to send mail from my localhost mail server to external mail server with the help of jboss 7 and apache james mail server.

      I have modified the standalone-full.xml as below:

       

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

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

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

                                <login name="nansjames" password="password"/>

                       </smtp-server>

                   </mail-session>

              <mail-session jndi-name="baseModule/EmailNotification"  from="emailaddress.com">

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

                              <login name="user" password="password" />

                        </smtp-server>

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

                               <login name="user" password="password" />

                        </pop3-server>

                 </mail-session>

          </subsystem>

      ...

          <outbound-socket-binding name="mail-smtp">

                  <remote-destination host="remotehost" port="25"/>

            </outbound-socket-binding>

       

            <outbound-socket-binding name="mail-pop3">

                  <remote-destination host="remotehost" port="25"/>

            </outbound-socket-binding>          

      In config.xml in Apache James 2.3

       

      <processor name="transport">

      <mailet match="All" class="RemoteDelivery">

           <gateway> smtp.gmail.com </gateway>

              <gatewayPort>25</gatewayPort>

      .....

          <gatewayusername>nansjames</gatewayusername>

              <gatewayPassword>password</gatewayPassword>

      </processor>

       

      Started telnet localhost 4555 and added the users..

       

      Java program:

      @WebServlet(value="/SendNewMail")

      public class SendNewMail extends HttpServlet

      {

          @Resource(mappedName="java:jboss/mail/Default")

          private Session mailSession;

       

      // Get system properties

          Properties properties = System.getProperties();

       

       

          //SmtpAuthenticator authentication = new SmtpAuthenticator();

          //Session session = Session.getDefaultInstance(properties,authentication);

          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

              {

       

                  PrintWriter out=response.getWriter();

                  try    {

                      MimeMessage m = new MimeMessage(mailSession);

                      Address from = new InternetAddress("nansjames");

                      Address[] to = new InternetAddress[] {new InternetAddress("mygmailaccount@gmail.com") };

       

                      m.setFrom(from);

                      m.setRecipients(Message.RecipientType.TO, to);

                      m.setSubject("JBoss AS 7 Mail");

                      m.setSentDate(new java.util.Date());

                      m.setContent("Mail sent from JBoss AS 7","text/plain");

                      Transport.send(m);

                      out.println("Mail sent!");

                  }

                  catch (javax.mail.MessagingException e)

                  {

                      e.printStackTrace();

                      out.println("Error in Sending Mail: "+e);

                  }

              }

          }

      }

       

      I am received "Mail sent"message in the server but no mail is sending to the gmail account.

       

      Please help where i have done the mistake and what other changes i have to made. Do i need to enter domain name in domainlist but which is available in apache-james-3.0 beta 4.

      Thanks in advance.Can anyone reply for this question?

      Nans