• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Email Logging With Non-Default Port With Log4J

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been trying to figure out a way that I can configure log4J to send error emails. The problem is that our admins require me to use a non-default port to connect to the SMTP server. Log4J's SMTPAppender does not seem to be able to handle any port other than 25. Does anyone have any suggestions? Is there another implementation of an SMTPAppender available that I can use that allows the port to be specified? Thanks so much. Below is the configuration I have so far:

<appender name="SMTP" class="org.apache.log4j.net.SMTPAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Threshold" value="ERROR"/>
<param name="To" value="fake@fake.com"/>
<param name="From" value="fake@fake.com"/>
<param name="Subject" value="JBoss Sever Errors"/>
<param name="SMTPHost" value="fake.fake.com"/>
<param name="BufferSize" value="1"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ABSOLUTE},%c{1}] %m%n"/>
</layout>
</appender>
[ January 25, 2006: Message edited by: Anthony Watson ]
 
Marshal
Posts: 27214
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not write your own? You just have to subclass the SMTPAppender class, and you have the source code to work from:

1. Add an int "port" variable with getter and setter.
2. Override the activateOptions() method with a copy of the log4j code that uses the "port" variable.
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did end up writing my own and it is very simple. SMTPAppender uses JavaMail APIs behind the scenes. I just found where SMTPHost was being set in the SMTPAppender and then added getter/setter methods for smtpPort and the following:

if (smtpPort != null) {
props.put("mail.smtp.port", smtpPort);
}

Session session = Session.getInstance(props, null);
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic