geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jakob Færch (Trifork)" <...@trifork.com>
Subject Problems sending JavaMail mail over SMTP transport
Date Wed, 21 Dec 2005 12:41:34 GMT
I'm trying to make an application send an email using JavaMail.

The code sending the mail looks like this:
     /**
      * This method creates an email message and sends it using the
      * J2EE mail services
      * @param mailContent contains the message contents to send
      */
     public void createAndSendMail(String emailAddress, String subject, 
String mailContent, Locale locale) throws MailerException {
         try {
             InitialContext ic = new InitialContext();
             Session session = (Session) ic.lookup(JNDINames.MAIL_SESSION);
             Message msg = new MimeMessage(session);
             msg.setFrom();
             msg.setRecipients(Message.RecipientType.TO,
                      InternetAddress.parse(emailAddress, false));
             msg.setSubject(subject);
             String contentType = "text/html";
             StringBuffer sb = new StringBuffer(mailContent);
             msg.setDataHandler(new DataHandler(
                               new ByteArrayDataSource(sb.toString(), 
contentType)));
             msg.setHeader("X-Mailer", "JavaMailer");
             msg.setSentDate(new Date());
             Transport.send(msg);

The ejb-jar for the bean in which the code is executed features this 
snippet:
         <resource-ref>
           <res-ref-name>mail/MailSession</res-ref-name>
           <res-type>javax.mail.Session</res-type>
           <res-auth>Container</res-auth>
           <res-sharing-scope>Shareable</res-sharing-scope>
         </resource-ref>


The geronimo plan has the following to match it:


     <gbean name="mail/MailSession" 
class="org.apache.geronimo.mail.MailGBean" />
     <gbean name="mail/MailSession" 
class="org.apache.geronimo.mail.SMTPTransportGBean">
         <attribute name="host">my.valid.smtphost</attribute>
         <attribute name="port">25</attribute>
     </gbean>

This is the behaviour I can observe using a debugger:
  - A SMTPTransportGBean is instantiated with the correct host parameter
  - The code runs fine, and no exception is thrown from
    the call to Transport.send
  - The Session object looked up in the InitialContext doesn't have
    any properties; I was expection it to have at least a "host"
    property. I don't know a lot about JavaMail, so it might be that
    the session object is fine.
  - I can't find anything in the log which seems related, neither at
    server startup time or at the time the sending code is executed
  - Neither the constructor nor the SendMessage method in
    org.apache.geronimo.javamail.transport.smtp.SMTPTransport is
    called
  - Using localhost for smtp host and a logging tcp proxy, it seems
    that no traffic is generated for the smtp host port 25.

Do I need som additional "wiring" to make smtp sending work? I can see 
that the javamail-transport module has a javamail.default.providers file 
instruction Javamail to use SMTPTransport for smtp. Do I need to do 
anything to facilitate this at runtime?

Mime
View raw message