请参阅下面的log4j.xml文件。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="email" class="org.apache.log4j.net.SMTPAppender">
<param name="BufferSize" value="1" />
<param name="SMTPHost" value="smtp.mail.yahoo.com" />
<param name="SMTPPort" value="587" />
<param name="SMTPUsername" value="email@yahoo.in" />
<param name="SMTPPassword" value="password" />
<param name="From" value="email@yahoo.in" />
<param name="To" value="email@gmail.com" />
<param name="Subject" value="Error Log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[${name}] - %d{ISO8601} - %X{login} - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="error" />
<param name="LevelMax" value="fatal" />
</filter>
</appender>
<root>
<level value="info" />
<appender-ref ref="email" />
</root>
</log4j:configuration>
执行此程序时,我收到以下错误消息:
log4j:ERROR Error occured while sending e-mail notification.
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required
非常感谢任何帮助!!!
答案 0 :(得分:1)
在smtp appender配置中添加以下内容,并使用log4j 1.2.17版将端口更改为465
<param name="SMTPProtocol" value="smtps" />
答案 1 :(得分:0)
将javax.mail升级到1.4.7对我有用。
compile('javax.mail:mail:1.4.7')