简体   繁体   English

为gmail设置log4j,无法识别System.setProperty(“ mail.smtps.port”,“ 587”)

[英]setting up log4j for gmail, does not recognize System.setProperty(“mail.smtps.port”, “587”)

I am trying to setup a smtpappender for log4j using gmail as the smtp host. 我正在尝试使用gmail作为smtp主机为log4j设置一个smtpappender。

I have read that the port number needs to be 465 or 587 (depending on tls or ssl) and that log4j for some reason doesnt allow a different port to be set inside log4j.properties configuration file. 我已经读过,端口号需要为465或587(取决于tls或ssl),由于某种原因,log4j不允许在log4j.properties配置文件中设置其他端口。

I have read that the best way of doing this would be to use System.setProperty which would change the default javaxmail port to gmail. 我已经读到,做到这一点的最佳方法是使用System.setProperty,它将默认的javaxmail端口更改为gmail。

However when I try to set the System.property entries the the default port still remains as 25 但是,当我尝试设置System.property条目时,默认端口仍保持为25

System.setProperty("mail.smtp.starttls.enable", "true"); System.setProperty(“ mail.smtp.starttls.enable”,“ true”); System.setProperty("mail.smtp.port", "587"); System.setProperty(“ mail.smtp.port”,“ 587”);

I was wondering if someone could help me out, I am open to suggestions, I just need to smtpAppender to work for gmail, dont really care how to get it to work. 我想知道是否有人可以帮助我,我乐于接受建议,我只需要smtpAppender来使用gmail,就不在乎如何使它工作。

Thanks 谢谢

You need to create a custom SMTPAppender and specify it in the log4j config file. 您需要创建一个自定义SMTPAppender并在log4j配置文件中指定它。 Google learns me that there are at least two blog posts which describes how to do it: here and here . Google向我了解到,至少有两个博客文章描述了如何执行此操作: 此处此处

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java Mail:在端口587上通过Gmail SMTP发送邮件时,操作超时 - Java Mail: Operation timeout while sending mail over Gmail SMTP on port 587 无法使用smtp.gmail.com,端口587从vbs脚本发送邮件 - Can not send mail using smtp.gmail.com, port 587 from vbs script 端口 587 上的 GMail SMTP STARTTLS 不再有效 - GMail SMTP STARTTLS on Port 587 no longer works 在本地主机上发送邮件有效,但是当部署到网络服务器时,我得到无法连接到主机,端口:smtp.gmail.com,587 - Sending mail on localhost works, but when deployed to webserver I get Couldn't connect to host, port: smtp.gmail.com, 587 com.sun.mail.util.MailConnectException:无法连接到主机,端口:smtp.gmail.com,587; 超时-1 - com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 587; timeout -1 javax.mail.MessagingException:无法连接到SMTP主机:smtp.gmail.com,端口:587; java.net.NoRouteToHostException:主机没有路由 - javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587; java.net.NoRouteToHostException: No route to host Log4j SMTP将错误消息发送到电子邮件 - Log4j SMTP Send Error Messages to E-Mail Log4j以编程方式设置SMTP设置不能完全正常工作 - Log4j programmatically setting SMTP settings is not completely working 专用子网中的EC2 587端口上的Gmail SMTP超时 - Gmail SMTP timeout on 587 port, EC2 in private subnet 证书必须有效才能使用CDOSYS和SMTPS进行邮寄吗? - Does a certificate have to be valid to mail using CDOSYS and SMTPS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM