4

I'm trying to configure log4j to use the SMTPAppender but I keep getting relay access denied errors. I get this error when executing my code on my laptop AND straight from my shared hosting environment.

Here's the relevant config:

#CONFIGURE SMTP
log4j.appender.email=org.apache.log4j.net.SMTPAppender
log4j.appender.email.SMTPHost=mydomain.com
log4j.appender.email.SMTPUsername=myuser
log4j.appender.email.SMTPPassword=mypw
log4j.appender.email.From=myuser@mydomain.com
log4j.appender.email.BufferSize=1
log4j.appender.email.EvaluatorClass=TriggerLogEvent
log4j.appender.email.layout=org.apache.log4j.PatternLayout
log4j.appender.email.layout.ConversionPattern=%m

If I switch to log4j.appender.email.SMTPHost=mail.mydomain.com instead then I get authentication errors. My hosting is on DreamHost so bonus points if anyone has set up log4j SMTPAppender using a DreamHost email account.

Owen
  • 22,247
  • 13
  • 42
  • 47

2 Answers2

4

Turns out I just had the properties all wrong. Should be:

#CONFIGURE SMTP
log4j.appender.email=org.apache.log4j.net.SMTPAppender
log4j.appender.email.SMTPHost=mail.mydomain.com
log4j.appender.email.SMTPUsername=myuser@mydomain.com
log4j.appender.email.SMTPPassword=mypw
log4j.appender.email.From=myuser@mydomain.com
log4j.appender.email.BufferSize=1
log4j.appender.email.EvaluatorClass=TriggerLogEvent
log4j.appender.email.layout=org.apache.log4j.PatternLayout
log4j.appender.email.layout.ConversionPattern=%m
Owen
  • 22,247
  • 13
  • 42
  • 47
  • This gives me: _java.lang.ClassNotFoundException: TriggerLogEvent_. Is this for an old version of log4j? – Drew Noakes Dec 18 '12 at 10:11
  • 4
    Turns out that `TriggerLogEvent` is a downloadable class that you can use if you need to log levels other than ERROR. More information here: http://stackoverflow.com/a/8170636/24874 – Drew Noakes Dec 18 '12 at 10:26
0

SMTPHost should point to your mail server (so, mail.mydomain.com for Dreamhost). Can you send mail manually if you telnet to port 25 and pass credentials by hand?

Don Werve
  • 5,100
  • 2
  • 26
  • 32