Bug 45109 - SMTPAppender uses wrong property for mail server
Summary: SMTPAppender uses wrong property for mail server
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.2
Hardware: PC Windows Vista
: P2 normal
Target Milestone: ---
Assignee: log4j-dev
Depends on:
Reported: 2008-05-31 14:14 UTC by Christian Schneider
Modified: 2008-10-15 12:55 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Christian Schneider 2008-05-31 14:14:57 UTC
SMTPAppender always sends to localhost as it seems to set the wrong property in the session. 

In the createSession method SMTPAppender sets the property "mail.smtp.host"
if (smtpHost != null) {
      props.put("mail.smtp.host", smtpHost);

Then it calls Transport.send which tries to read the protocol from the url
in the class Service
if (url != null) {
                host = url.getHost();
                // it is possible that this could return null (rare).  If it does, try to get a
                // value from a protocol specific session variable.
                if (host == null) {
                    host = session.getProperty("mail." + protocol + ".host");

But as url is null the mail.smtp.host is not read correctly. So host stays null and the appender connects to localhost.
Comment 1 Curt Arnold 2008-10-15 12:55:21 UTC
As described, it would seem to imply that SMTPAppender should never work except for SMTP servers on the same machine.  That isn't consistent with my experience and it seems unlikely that if the problem was that universal, it would not have been reported previously.

I am successfully and sending email messages using SSL to smtp.google.com and if I turn off SSL, I get an exception message that specifies "Could not connect to SMTP host: smtp.google.com, port 25" which indicates that the JavaMail implementation is not ignoring the specified SMTPHost.

You did not identify the source for your snippet of Transport.send().  If you are using an atypical implementation, it would be good if you would identify it.  If SMTPAppender works with more common JDK libraries and not with yours, then it would likely be a problem with your JDK's implementation of Transport.send().