[英]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.