Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

java - What is the proper way to configure SMTPAppender in log4j?

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
[email protected]
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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
[email protected]
log4j.appender.email.SMTPPassword=mypw
[email protected]
log4j.appender.email.BufferSize=1
log4j.appender.email.EvaluatorClass=TriggerLogEvent
log4j.appender.email.layout=org.apache.log4j.PatternLayout
log4j.appender.email.layout.ConversionPattern=%m

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...