为什么我无法通过Log4j SMTPAppender发送电子邮件?

时间:2015-09-26 22:11:28

标签: java email smtp log4j smtpappender

我使用Log4j 1.2.17进行记录。我想向我的电子邮件发送错误消息但我有一些问题。 这是我的properies文件:

log4j.appender.email=org.apache.log4j.net.SMTPAppender   
log4j.appender.email.Threshold=WARN
log4j.appender.email.SMTPHost=smtp.gmail.com
log4j.appender.email.SMTPUsername=myGmailAddress
log4j.appender.email.SMTPPassword=passwordToMyGmailAddress
log4j.appender.email.From=myGmailAddress
log4j.appender.email.To=anotherGmailAddress
log4j.appender.email.Subject=Log of messages
log4j.appender.email.layout=org.apache.log4j.SimpleLayout 

myGmailAddresspasswordToMyGmailAddress是我有效的Gmail和密码。 anotherGmailAddress - 另一个有效的gmail

当我运行我的应用程序时,我得到了这个:

log4j:ERROR Error occured while sending e-mail notification.
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25;
  nested exception is:
    java.net.ConnectException: Connection timed out: connect
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
    at javax.mail.Service.connect(Service.java:297)
    at javax.mail.Service.connect(Service.java:156)
    at javax.mail.Service.connect(Service.java:105)
    at javax.mail.Transport.send0(Transport.java:168)
    at javax.mail.Transport.send(Transport.java:98)
    at org.apache.log4j.net.SMTPAppender.sendBuffer(SMTPAppender.java:416)
    at org.apache.log4j.net.SMTPAppender.append(SMTPAppender.java:256)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.error(Category.java:305)
    at epam.lab.log4j.utils.Printer.printMessage(Printer.java:13)
    at epam.lab.log4j.Launcher.main(Launcher.java:35)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at java.net.Socket.connect(Socket.java:538)
    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)
    ... 15 more

我试图解决这个问题花了几个小时,但我找不到解决办法。 我尝试更改端口,禁用防病毒和防火墙,使用自定义SMTPAppender等...但它没有帮助...
任何想法如何解决这个问题?

0 个答案:

没有答案