java 在 log4j 中配置 SMTPAppender 的正确方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/778439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the proper way to configure SMTPAppender in log4j?
提问by Owen
I'm trying to configure log4j to use the SMTPAppenderbut 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.
我正在尝试配置 log4j 以使用 ,SMTPAppender但我不断收到中继访问被拒绝的错误。在我的笔记本电脑上直接从我的共享托管环境执行我的代码时,我收到此错误。
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.cominstead then I get authentication errors. My hosting is on DreamHost so bonus points if anyone has set up log4j SMTPAppenderusing a DreamHost email account.
如果我改用,log4j.appender.email.SMTPHost=mail.mydomain.com则会收到身份验证错误。我的主机在 DreamHost 上,因此如果有人SMTPAppender使用 DreamHost 电子邮件帐户设置了 log4j ,则可以获得积分。
采纳答案by Owen
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
回答by Don Werve
SMTPHost should point to your mail server (so, mail.mydomain.comfor Dreamhost). Can you send mail manually if you telnet to port 25 and pass credentials by hand?
SMTPHost 应该指向您的邮件服务器(所以,mail.mydomain.com对于 Dreamhost)。如果您 telnet 到端口 25 并手动传递凭据,您可以手动发送邮件吗?

