You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Nicko Cadell <ni...@neoworks.com> on 2005/04/02 20:42:37 UTC

RE: SmtpAppender not working

Baron,

The runtime provides SMTP support through the MailMessage. Microsoft
have chosen to implement it using their CDO library. Usually CDO works
fine, however it is possible for it to be disabled.

While it should be simple to implement a system that sends mail directly
via port 25 I'm not sure it this is necessarily the best use of
resources as CDO works out of the box.

If someone wants to look at doing this it may be best to make the mail
sending functionality of the SmtpAppender pluggable between the current
MailMessage and an independent implementation.

Nicko

> -----Original Message-----
> From: Baron Schwartz [mailto:baron@sequent.org] 
> Sent: 24 March 2005 14:27
> To: Log4NET User
> Subject: RE: SmtpAppender not working
> 
> Thanks Nicko.
> 
> I have searched more on the various error messages and found 
> that indeed it is a problem with CDO on my laptop.  When I 
> configure the logging on the production machines, it works 
> fine.  I'm not familiar with what CDO is or how/why it's not 
> working on my laptop, other than maybe I borked it up when I 
> turned off every non-essential service (I believe the Systems 
> staff has all sorts of stuff running on the production 
> servers... not my job).
> 
> I did try using the fully qualified name of the SMTP machine, 
> and even its IP address; like I said I've had no problems 
> with sending to that machine with the SMTP software I've 
> written (telnet, too).
> 
> I looked through the source code for the SmtpAppender more.  
> I'm not sure how many people would use the more advanced 
> settings, such as sending through the credentials of the 
> process under which log4net runs -- and I know it's bad to 
> reinvent the wheel.  But, just to play devil's advocate, is 
> there any justification for an SMTP appender which sends via 
> plain SMTP, without relying on System.Web.Mail?  SMTP is 
> trivial to implement, and this might ease the problems, and 
> may even be more efficient as an appender.  I saw a lot of 
> griping on the Internet about this CDO issue, with no real 
> resolutions.  It sounds like there may be some Microsoftish 
> "extend the standard" issues with CDO.  But I'm no expert on 
> it, as I said.
> 
> Baron
> 
> On Thu, 24 Mar 2005, Nicko Cadell wrote:
> 
> >   "The transport failed to connect to the server"
> >
> > It looks like the CDO implementation on the machine cannot 
> access the 
> > mail server.
> >
> > You config is fine for accessing an unauthenticated mail relay.
> >
> > Can you try telneting directly into your mail server from the box 
> > running your app:
> >
> >   telnet madrid 25
> >
> > Type in "HELO" the server should respond with some helpful message. 
> > Type "QUIT" to exit. Does this work?
> > Have you tried specifying the smtpHost as a fully qualified 
> domain name?
> > or as an IP address? It may be that the CDO library cannot 
> resolve the 
> > name.
> >
> > Are you running any local firewall software that may be blocking 
> > outbound connections, for some or all users or applications?
> >
> > There seems to be several other people having the same problem with 
> > various fixes discussed here:
> >
> > 
> http://www.google.co.uk/search?q=transport+failed+to+connect+to+the+se
> > rv
> > er+CDO
> >
> > Nicko
> >
> >
> > > -----Original Message-----
> > > From: Baron Schwartz [mailto:baron@sequent.org]
> > > Sent: 21 March 2005 16:57
> > > To: log4net-user@logging.apache.org
> > > Subject: SmtpAppender not working
> > >
> > > Hi,
> > >
> > > I've searched the web and read the manual and some of the 
> code, but 
> > > feel free to point me somewhere there's an answer... I can't find 
> > > much on this.
> > >
> > > My SmtpAppender isn't able to connect to the smtpHost.  I'm on 
> > > Windows using MS framework v1.1.  Here's my config file 
> (me@me.com 
> > > is bogus -- I'm using a real value), test code, and the error I'm 
> > > getting in the console window when the log fails to 
> email.  The SMTP 
> > > server, madrid, is an open relay inside our firewall, 
> which requires 
> > > no authentication or anything.
> > > I send mail with it from a bunch of other apps.
> > >
> > > One thing I did notice, is that apparently there are some other 
> > > parameters I could be putting in the config file, but I'm 
> not sure 
> > > what they should be (the example config seems to be incomplete).  
> > > Starting at SmtpAppender.cs, and looking at its 
> properties, it looks 
> > > like username, password etc *could* be put in the config file.  I 
> > > didn't read through enough of the code to determine what the 
> > > parameters would be named, because they wouldn't be necessary for 
> > > this application, but if someone points me to how I can 
> find it out 
> > > (short of stepping through the code) I'm happy to update the 
> > > example, or augment it with a more complete example.
> > >
> > > Thanks for any help.
> > >
> > > --- Snip ---
> > > <?xml version="1.0" encoding="utf-8" ?> <configuration>
> > >     <configSections>
> > >         <section name="log4net"
> > > type="log4net.Config.Log4NetConfigurationSectionHandler, 
> log4net" />
> > >     </configSections>
> > >     <log4net>
> > >         <appender name="SmtpAppender"
> > > type="log4net.Appender.SmtpAppender">
> > >             <to value="me@me.com" />
> > >             <from value="me@me.com" />
> > >             <subject value="Baaaaad error" />
> > >             <smtpHost value="madrid" />
> > >             <bufferSize value="4" />
> > >             <lossy value="true" />
> > >             <evaluator type="log4net.Core.LevelEvaluator">
> > >                 <threshold value="WARN"/>
> > >             </evaluator>
> > >             <layout type="log4net.Layout.PatternLayout">
> > >                 <conversionPattern value="%-5p %-20t %d 
> %c line %L%n 
> > > %m%n" />
> > >             </layout>
> > >         </appender>
> > >         <root>
> > >             <appender-ref ref="SmtpAppender" />
> > >         </root>
> > >     </log4net>
> > >     <appSettings>
> > >     </appSettings>
> > > </configuration>
> > > --- Snip ---
> > > using System;
> > > using log4net;
> > > using log4net.Config;
> > > namespace TestHarness {
> > >     public class TestHarness {
> > >         static readonly ILog log =
> > > LogManager.GetLogger(typeof(TestHarness));
> > >         public static void Main(string[] args) {
> > >             XmlConfigurator.Configure();
> > >             log.Warn("hey, this is an error!");
> > >         }
> > >     }
> > > }
> > > --- Snip ---
> > > log4net:ERROR [SmtpAppender] Error occurred while sending e-mail 
> > > notification.
> > > System.Web.HttpException: Could not access 'CDO.Message'
> > > object. ---> System.Ref
> > > lection.TargetInvocationException: Exception has been 
> thrown by the 
> > > target of an  invocation. ---> 
> > > System.Runtime.InteropServices.COMException
> > > (0x80040213): The
> > > transport failed to connect to the server.
> > >
> > >    --- End of inner exception stack trace ---
> > >    at System.RuntimeType.InvokeDispMethod(String name, 
> BindingFlags 
> > > invokeAttr, Object target, Object[] args, Boolean[] 
> byrefModifiers, 
> > > Int32 culture, String[]
> > > namedParameters)
> > >    at System.RuntimeType.InvokeMember(String name, BindingFlags 
> > > invokeAttr, Bind er binder, Object target, Object[] args, 
> > > ParameterModifier[] modifiers, CultureI nfo culture, String[] 
> > > namedParameters)
> > >    at System.Type.InvokeMember(String name, BindingFlags 
> invokeAttr, 
> > > Binder bind er, Object target, Object[] args)
> > >    at System.Web.Mail.LateBoundAccessHelper.CallMethod(Type
> > > type, Object obj, St ring methodName, Object[] args)
> > >    at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object
> > > obj, String method Name, Object[] args)
> > >    --- End of inner exception stack trace ---
> > >    at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object
> > > obj, String method Name, Object[] args)
> > >    at System.Web.Mail.CdoSysHelper.Send(MailMessage message)
> > >    at System.Web.Mail.SmtpMail.Send(MailMessage message)
> > >    at log4net.Appender.SmtpAppender.SendBuffer(LoggingEvent[] 
> > > events)
> > >
> >
> >
> 

RE: SmtpAppender not working

Posted by Baron Schwartz <ba...@sequent.org>.
I agreed with you until I just thought of something: MailMessage uses 
static properties to set the SMTP server etc.  Tell me if I'm wrong, but 
that affects anything that's using MailMessage, on a per-process basis. 
So, if my system is using MailMessage to send email, and I set my message 
up and get it ready to send but then make a call to logging functionality 
before actually sending the mail, it might go through a different SMTP 
server than I intended, right?

I'm not sure if this is a big problem, but it could be a subtle one.  And 
multi-threading issues could come into play too.  That could get tough to 
debug.

Baron

-- 
"I am as bad as the worst, but, thank God, I am as good as the best."
     - Walt Whitman

On Sat, 2 Apr 2005, Nicko Cadell wrote:

> Baron,
>
> The runtime provides SMTP support through the MailMessage. Microsoft
> have chosen to implement it using their CDO library. Usually CDO works
> fine, however it is possible for it to be disabled.
>
> While it should be simple to implement a system that sends mail directly
> via port 25 I'm not sure it this is necessarily the best use of
> resources as CDO works out of the box.
>
> If someone wants to look at doing this it may be best to make the mail
> sending functionality of the SmtpAppender pluggable between the current
> MailMessage and an independent implementation.
>
> Nicko
>
>> -----Original Message-----
>> From: Baron Schwartz [mailto:baron@sequent.org]
>> Sent: 24 March 2005 14:27
>> To: Log4NET User
>> Subject: RE: SmtpAppender not working
>>
>> Thanks Nicko.
>>
>> I have searched more on the various error messages and found
>> that indeed it is a problem with CDO on my laptop.  When I
>> configure the logging on the production machines, it works
>> fine.  I'm not familiar with what CDO is or how/why it's not
>> working on my laptop, other than maybe I borked it up when I
>> turned off every non-essential service (I believe the Systems
>> staff has all sorts of stuff running on the production
>> servers... not my job).
>>
>> I did try using the fully qualified name of the SMTP machine,
>> and even its IP address; like I said I've had no problems
>> with sending to that machine with the SMTP software I've
>> written (telnet, too).
>>
>> I looked through the source code for the SmtpAppender more.
>> I'm not sure how many people would use the more advanced
>> settings, such as sending through the credentials of the
>> process under which log4net runs -- and I know it's bad to
>> reinvent the wheel.  But, just to play devil's advocate, is
>> there any justification for an SMTP appender which sends via
>> plain SMTP, without relying on System.Web.Mail?  SMTP is
>> trivial to implement, and this might ease the problems, and
>> may even be more efficient as an appender.  I saw a lot of
>> griping on the Internet about this CDO issue, with no real
>> resolutions.  It sounds like there may be some Microsoftish
>> "extend the standard" issues with CDO.  But I'm no expert on
>> it, as I said.
>>
>> Baron
>>
>> On Thu, 24 Mar 2005, Nicko Cadell wrote:
>>
>>>   "The transport failed to connect to the server"
>>>
>>> It looks like the CDO implementation on the machine cannot
>> access the
>>> mail server.
>>>
>>> You config is fine for accessing an unauthenticated mail relay.
>>>
>>> Can you try telneting directly into your mail server from the box
>>> running your app:
>>>
>>>   telnet madrid 25
>>>
>>> Type in "HELO" the server should respond with some helpful message.
>>> Type "QUIT" to exit. Does this work?
>>> Have you tried specifying the smtpHost as a fully qualified
>> domain name?
>>> or as an IP address? It may be that the CDO library cannot
>> resolve the
>>> name.
>>>
>>> Are you running any local firewall software that may be blocking
>>> outbound connections, for some or all users or applications?
>>>
>>> There seems to be several other people having the same problem with
>>> various fixes discussed here:
>>>
>>>
>> http://www.google.co.uk/search?q=transport+failed+to+connect+to+the+se
>>> rv
>>> er+CDO
>>>
>>> Nicko
>>>
>>>
>>>> -----Original Message-----
>>>> From: Baron Schwartz [mailto:baron@sequent.org]
>>>> Sent: 21 March 2005 16:57
>>>> To: log4net-user@logging.apache.org
>>>> Subject: SmtpAppender not working
>>>>
>>>> Hi,
>>>>
>>>> I've searched the web and read the manual and some of the
>> code, but
>>>> feel free to point me somewhere there's an answer... I can't find
>>>> much on this.
>>>>
>>>> My SmtpAppender isn't able to connect to the smtpHost.  I'm on
>>>> Windows using MS framework v1.1.  Here's my config file
>> (me@me.com
>>>> is bogus -- I'm using a real value), test code, and the error I'm
>>>> getting in the console window when the log fails to
>> email.  The SMTP
>>>> server, madrid, is an open relay inside our firewall,
>> which requires
>>>> no authentication or anything.
>>>> I send mail with it from a bunch of other apps.
>>>>
>>>> One thing I did notice, is that apparently there are some other
>>>> parameters I could be putting in the config file, but I'm
>> not sure
>>>> what they should be (the example config seems to be incomplete).
>>>> Starting at SmtpAppender.cs, and looking at its
>> properties, it looks
>>>> like username, password etc *could* be put in the config file.  I
>>>> didn't read through enough of the code to determine what the
>>>> parameters would be named, because they wouldn't be necessary for
>>>> this application, but if someone points me to how I can
>> find it out
>>>> (short of stepping through the code) I'm happy to update the
>>>> example, or augment it with a more complete example.
>>>>
>>>> Thanks for any help.
>>>>
>>>> --- Snip ---
>>>> <?xml version="1.0" encoding="utf-8" ?> <configuration>
>>>>     <configSections>
>>>>         <section name="log4net"
>>>> type="log4net.Config.Log4NetConfigurationSectionHandler,
>> log4net" />
>>>>     </configSections>
>>>>     <log4net>
>>>>         <appender name="SmtpAppender"
>>>> type="log4net.Appender.SmtpAppender">
>>>>             <to value="me@me.com" />
>>>>             <from value="me@me.com" />
>>>>             <subject value="Baaaaad error" />
>>>>             <smtpHost value="madrid" />
>>>>             <bufferSize value="4" />
>>>>             <lossy value="true" />
>>>>             <evaluator type="log4net.Core.LevelEvaluator">
>>>>                 <threshold value="WARN"/>
>>>>             </evaluator>
>>>>             <layout type="log4net.Layout.PatternLayout">
>>>>                 <conversionPattern value="%-5p %-20t %d
>> %c line %L%n
>>>> %m%n" />
>>>>             </layout>
>>>>         </appender>
>>>>         <root>
>>>>             <appender-ref ref="SmtpAppender" />
>>>>         </root>
>>>>     </log4net>
>>>>     <appSettings>
>>>>     </appSettings>
>>>> </configuration>
>>>> --- Snip ---
>>>> using System;
>>>> using log4net;
>>>> using log4net.Config;
>>>> namespace TestHarness {
>>>>     public class TestHarness {
>>>>         static readonly ILog log =
>>>> LogManager.GetLogger(typeof(TestHarness));
>>>>         public static void Main(string[] args) {
>>>>             XmlConfigurator.Configure();
>>>>             log.Warn("hey, this is an error!");
>>>>         }
>>>>     }
>>>> }
>>>> --- Snip ---
>>>> log4net:ERROR [SmtpAppender] Error occurred while sending e-mail
>>>> notification.
>>>> System.Web.HttpException: Could not access 'CDO.Message'
>>>> object. ---> System.Ref
>>>> lection.TargetInvocationException: Exception has been
>> thrown by the
>>>> target of an  invocation. --->
>>>> System.Runtime.InteropServices.COMException
>>>> (0x80040213): The
>>>> transport failed to connect to the server.
>>>>
>>>>    --- End of inner exception stack trace ---
>>>>    at System.RuntimeType.InvokeDispMethod(String name,
>> BindingFlags
>>>> invokeAttr, Object target, Object[] args, Boolean[]
>> byrefModifiers,
>>>> Int32 culture, String[]
>>>> namedParameters)
>>>>    at System.RuntimeType.InvokeMember(String name, BindingFlags
>>>> invokeAttr, Bind er binder, Object target, Object[] args,
>>>> ParameterModifier[] modifiers, CultureI nfo culture, String[]
>>>> namedParameters)
>>>>    at System.Type.InvokeMember(String name, BindingFlags
>> invokeAttr,
>>>> Binder bind er, Object target, Object[] args)
>>>>    at System.Web.Mail.LateBoundAccessHelper.CallMethod(Type
>>>> type, Object obj, St ring methodName, Object[] args)
>>>>    at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object
>>>> obj, String method Name, Object[] args)
>>>>    --- End of inner exception stack trace ---
>>>>    at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object
>>>> obj, String method Name, Object[] args)
>>>>    at System.Web.Mail.CdoSysHelper.Send(MailMessage message)
>>>>    at System.Web.Mail.SmtpMail.Send(MailMessage message)
>>>>    at log4net.Appender.SmtpAppender.SendBuffer(LoggingEvent[]
>>>> events)
>>>>
>>>
>>>
>>
>
>