問題が発生したときに、Log4j で SMTP 電子メールを送信しようとすると、大きな問題が発生します。これが私のコードです:
final Properties properties = new Properties();
final String strProperties = "log4j.rootLogger=ERROR, console, smtp\n"
+ "log4j.appender.console=org.apache.log4j.ConsoleAppender\n"
+ "log4j.appender.console.Target=System.out\n"
+ "log4j.appender.console.layout=org.apache.log4j.PatternLayout\n"
+ "log4j.appender.console.layout.ConversionPattern=%-5p: %c - %m%n\n"
+ "log4j.appender.smtp=org.apache.log4j.net.SMTPAppender\n"
+ "log4j.appender.smtp.EvaluatorClass=com.blah.blah.log4j.TriggerOnError\n"
+ "log4j.appender.smtp.SMTPHost=localhost\n"
+ "log4j.appender.smtp.From=mml_automation@blah.com\n"
+ "log4j.appender.smtp.To=ccmis@blah.com\n"
+ "log4j.appender.smtp.Subject=BagBox ERROR\n"
+ "log4j.appender.smtp.layout=org.apache.log4j.PatternLayout\n"
+ "log4j.appender.smtp.threshold=INFO\n"
+ "log4j.appender.smtp.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} : %-40c : %-5p %x - %m %n\n"
+ "log4j.logger.com.blah.blah.service.BagBoxService=INFO, smtp\n"
+ "log4j.logger.com.blah.blah.security=INFO, smtp\n"
+ "log4j.logger.org.springframework.core=ERROR, console, smtp\n"
+ "log4j.logger.org.springframework.beans=ERROR, console, smtp\n"
+ "log4j.logger.org.springframework.context=ERROR, console, smtp\n"
+ "log4j.logger.org.springframework.web=ERROR, console, smtp\n"
+ "log4j.logger.org.springframework.web.servlet.DispatcherServlet=ERROR, console, smtp\n"
+ "log4j.logger.org.springframework.security=ERROR, console, smtp\n"
+ "log4j.logger.org.springframework.aop=ERROR, console, smtp\n"
+ "log4j.logger.org.springframework.ui=ERROR, console, smtp\n";
final ByteArrayInputStream byteProperties = new ByteArrayInputStream(
strProperties.getBytes());
properties.load(byteProperties);
PropertyConfigurator.configure(properties);
コンソールに次のエラーが表示され続けます。
Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.SocketException: Network is unreachable: connect
IP アドレスで telnet を実行すると、正常に戻り、正常に接続できます。誰が私が間違っているのか教えてもらえますか? ありがとう。