Well, I'm not a super socket programmer, and not the best at architecting this kind of stuff, but I'd be willing to give it a shot if anyone else thinks it's worth doing. I don't want to do something that isn't welcome or useful, though.
Baron
--
"I am as bad as the worst, but, thank God, I am as good as the best."
- Walt WhitmanOn Thu, 7 Apr 2005, Nicko Cadell wrote:
I agree that the .NET API is not great with regard to the SmtpMail.SmtpServer. I would have preferred it if the server could have been passed on a per message basis. Also why did they choose to deliver mail functionality in the System.Web assembly?
We could change the appender to store the current SmtpMail.SmtpServer value, set the configured server before sending the mail, and then restore the previous value. That would probably reduce the impact down to 0.1% but make it even harder to track down!
Nicko
-----Original Message----- From: Baron Schwartz [mailto:[EMAIL PROTECTED] Sent: 06 April 2005 20:47 To: Log4NET User Subject: RE: SmtpAppender not working
Right - sorry, I didn't word that very well. You know what I mean, but in case others don't, here is the source code in src/Appender/SmtpAppender.cs:
280 : MailMessage mailMessage = new MailMessage(); 281 : mailMessage.Body = writer.ToString(); 282 : mailMessage.From = m_from; 283 : mailMessage.To = m_to; 284 : mailMessage.Subject = m_subject;
... and further on,
334 : if (m_smtpHost != null && m_smtpHost.Length > 0) 335 : { 336 : SmtpMail.SmtpServer = m_smtpHost; 337 : } 338 : 339 : SmtpMail.Send(mailMessage);
Personally, I don't like bugs that only occur 1% of the time. They are the hardest to track down and reproduce.
Baron
-- "I am as bad as the worst, but, thank God, I am as good as the best." - Walt Whitman
On Wed, 6 Apr 2005 [EMAIL PROTECTED] wrote:
SmtpServer is a static property of the SmtpMail class, butMailMessageMailMessage usesis an object - unique for each message.
I guess you might care which mail server you send the message from, but I can't see why it would matter for 99% of the cases.
-----Original Message----- From: Baron Schwartz [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 06, 2005 12:24 PM To: Log4NET User Subject: RE: SmtpAppender not working
I agreed with you until I just thought of something:static properties to set the SMTP server etc. Tell me ifI'm wrong,but that affects anything that's using MailMessage, on aper-process basis.through aSo, 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 gocould getdifferent 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. Thatthe best."tough to debug.
Baron
-- "I am as bad as the worst, but, thank God, I am as good asMicrosoft- Walt Whitman
On Sat, 2 Apr 2005, Nicko Cadell wrote:
Baron,
The runtime provides SMTP support through the MailMessage.the best usehave 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 necessarilyconfigure theof 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:[EMAIL PROTECTED] 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 Inot familiarlogging on the production machines, it works fine. I'mnon-essential servicewith what CDO is or how/why it's not working on my laptop, other than
maybe I borked it up when I turned off everywith sending(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 problemssettings,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 advancedunder whichsuch as sending through the credentials of the processmight easelog4net 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 thisappender. I sawthe problems, and may even be more efficient as anMicrosoftish "extenda
lot of griping on the Internet about this CDO issue, with no real resolutions. It sounds like there may be someas I said.the standard" issues with CDO. But I'm no expert on it,from the box
Baron
On Thu, 24 Mar 2005, Nicko Cadell wrote:
access the"The transport failed to connect to the server"
It looks like the CDO implementation on the machine cannotmail server.
You config is fine for accessing an unauthenticated mail relay.
Can you try telneting directly into your mail serverhelpful message.running your app:
telnet madrid 25
Type in "HELO" the server should respond with someproblem withdomain name?Type "QUIT" to exit. Does this work? Have you tried specifying the smtpHost as a fully qualifiedor as an IP address? It may be that the CDO library cannotresolve thename.
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 samehttp://www.google.co.uk/search?q=transport+failed+to+connect+to+the+various fixes discussed here:
can't finds ecode, butrv er+CDO
Nicko
-----Original Message----- From: Baron Schwartz [mailto:[EMAIL PROTECTED] Sent: 21 March 2005 16:57 To: [email protected] Subject: SmtpAppender not working
Hi,
I've searched the web and read the manual and some of thefeel free to point me somewhere there's an answer... Ierror I'm([EMAIL PROTECTED]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 fileis bogus -- I'm using a real value), test code, and theconfig file. Iemail. The SMTPgetting in the console window when the log fails towhich requiresserver, madrid, is an open relay inside our firewall,not sureno 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'mproperties, it lookswhat they should be (the example config seems to be incomplete). Starting at SmtpAppender.cs, and looking at itslike username, password etc *could* be put in thenecessary fordidn't read through enough of the code to determine what the parameters would be named, because they wouldn't besending e-mailfind it outthis application, but if someone points me to how I canlog4net" />(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,%c line %L%n</configSections> <log4net> <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender"> <to value="[EMAIL PROTECTED]" /> <from value="[EMAIL PROTECTED]" /> <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%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 whilethrown by thenotification. System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Ref lection.TargetInvocationException: Exception has beenBindingFlagstarget 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,byrefModifiers,invokeAttr, Object target, Object[] args, Boolean[]invokeAttr,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, BindingFlagsBinder 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)
