在log4j的properties中配置一下属性:
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.appender.mail.Threshold=ERROR
log4j.appender.mail.BufferSize=10
log4j.appender.mail.To=bastiaan.bakker@enovation.nl,simon.harinck@enovation.nl,albert.vthart@enovation.nl,marin.tapnoi@enovation.nl
log4j.appender.mail.From=helpdesk@enovation.nl
log4j.appender.mail.SMTPHost=eserver1.oper.enovation.net
log4j.appender.mail.Subject=Scheduler Error Log Message
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
这样配置后,如果log.error运行,就会向指定的邮箱中发邮件