You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jeremy Cowgar <jc...@cowgar.com> on 2004/06/15 05:15:48 UTC

Mail Session always uses localhost

I am having a bit of difficulties setting up a mail session. I learned 
that I must include mail.jar and activation.jar, also that their is a 
bug in 5.0.25, so I copied the appropriate file from 5.0.24 and made all 
that work. My problem lies in the fact that I cannot make tomcat talk to 
the SMTP host of my choice. It always uses localhost. Here is my config:

<Resource name="mail/Session" type="javax.mail.Session"/>
<ResourceParams name="mail/Session">
      <parameter>
        <name>mail.smtp.host</name>
        <value>mailout.sssnet.com</value>
      </parameter>
</ResourceParams>

My mailer code is:

            Context initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            Session session = (Session) envCtx.lookup("mail/Session");

            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(Constants.fromEmail));

            InternetAddress to[] = new InternetAddress[1];

            to[0] = new InternetAddress(toAddr);

            message.setRecipients(MimeMessage.RecipientType.TO, to);
            message.setSubject(subject);
            message.setContent(msg, "text/plain");
           
            Transport.send(message);

All this combined causes an email to be delivered to localhost:25 ... 
not mailout.sssnet.com. My local sendmail does not send mail externally, 
hense I setup for the SMTP server, the same one my email client uses. 
Just to verify my code is working correctly, I setup the same 
mail/Session JNDI name on a resin server (that I went to download for 
comparison) and the code works great, delivering it to 
mailout.sssnet.com like it should.

Does anyone have any ideas why this would be happening? To doubly verify 
(not just relying upon the logs) if I shutdown the sendmail daemon on my 
localhost, I recieve this error in the catalina.log:

javax.mail.SendFailedException: Sending failed;
  nested exception is:
        class javax.mail.MessagingException: Could not connect to SMTP 
host: localhost, port: 25;

Thanks,

Jeremy


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org