logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject RE: SmtpAppender and SSL
Date Thu, 16 Feb 2006 12:31:55 GMT
SmtpClient does not exist in .NET 1.1.

Try writing your own appender:

// untested
public class SmtpClientSmtpAppender : SmtpAppender
{
 override protected void SendBuffer(LoggingEvent[] events) 
 {
  try
  {
   StringWriter writer = new StringWriter(
    System.Globalization.CultureInfo.InvariantCulture);
   string t = Layout.Header;
   if (t != null)
   {
    writer.Write(t);
   }
   for(int i = 0; i < events.Length; i++) 
   {
   // Render the event and append the text to the buffer
   RenderLoggingEvent(writer, events[i]);
   }
   t = Layout.Footer;
   if (t != null)
   {
    writer.Write(t);
   }
   SmtpClient client = new SmtpClient(SmtpHost, Port);
   client.EnableSsl = true;
   client.Credentials = new NetworkCredential(Username, Password);
   MailMessage mail = new MailMessage(From,
   	To,
    	Subject,
    	writer.ToString());
  client.Send(mail);
  }
  catch(Exception e) 
  {
   ErrorHandler.Error("Error occurred while sending e-mail
notification.", e);
  }
 }
}

--- Vladimir Kovalenko <gaset.kovalenko@gmail.com> wrote:

> Here is the snippet:
> 
> SmtpClient client = new SmtpClient("smtp.gmail.com", 25);
> client.EnableSsl = true;
> client.Credentials = new NetworkCredential("username", "password");
> MailMessage mail = new MailMessage("from@gmail.com",
> 	"to@gmail.com",
> 	"subject",
> 	"body");
> client.Send(mail);
> 
> -----Original Message-----
> From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
> Sent: Thursday, February 16, 2006 1:39 AM
> To: Log4NET User
> Subject: RE: SmtpAppender and SSL
> 
> Could you post the snippet of code you're using in your test
> application application to send mail? Maybe your application is
> setting
> something that log4net isn't. Have you thought about taking your
> working code and overriding one or two methods in SmtpAppender?
> 
> <appender name="SmtpAppender"
> type="Company.Logging.GMailSmtpAppender">
>  ...
> </appender>
> 
> --- Vladimir Kovalenko <gaset.kovalenko@gmail.com> wrote:
> 
> > Yes. It works correctly.
> > 
> > -----Original Message-----
> > From: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
> > Sent: Wednesday, February 15, 2006 2:16 PM
> > To: Log4NET User
> > Subject: Re: SmtpAppender and SSL
> > 
> > Have you verified that you're able to send mail through GMail by
> > creating a simple console app and System.Web.Mail?
> > 
> > --- Vladimir Kovalenko <gaset.kovalenko@gmail.com> wrote:
> > 
> > > Hi.
> > > 
> > > I am currently experiencing the following problem: I am using
> > > SmtpAppender.
> > > E-mails are sent via smtp.gmail.com which uses SSL. My
> > configuration
> > > file
> > > looks like that:
> > > 
> > >  
> > > 
> > > <appender name="SmtpAppender"
> type="log4net.Appender.SmtpAppender">
> > >   <authentication value="Basic" />
> > >   <username value="username" />
> > >   <password value="password" />
> > >   <to value="one@gmail.com" />
> > >   <from value="two@gmail.com" />
> > >   <subject value="Logging information" />
> > >   <smtpHost value="smtp.gmail.com" />
> > >   <bufferSize value="512" />
> > >   <lossy value="true" />
> > >   <evaluator type="log4net.Core.LevelEvaluator">
> > >     <threshold value="INFO"/>
> > >   </evaluator>
> > >   <layout type="log4net.Layout.PatternLayout">
> > >     <conversionPattern value="%newline%date [%thread] %-5level
> > > %logger
> > > [%property{NDC}] - %message%newline%newline%newline" />
> > >   </layout>
> > > </appender>
> > > 
> > >  
> > > 
> > > I receive the following runtime error:
> > > 
> > >  
> > > 
> > > log4net:ERROR [SmtpAppender] Error occurred while sending e-mail
> > > notification.
> > > System.Web.HttpException: The server rejected the sender address.
> > The
> > > server
> > > response was: 530 5.7.0 Must issue a STARTTLS command first
> > > a29sm294756qbd
> > > ---> System.Reflection.TargetInvocationException: Exception has
> > been
> > > thrown
> > > by the target of an invocation. --->
> > > System.Runtime.InteropServices.COMException (0x8004020E): The
> > server
> > > rejected the sender address. The server response was: 530 5.7.0
> > Must
> > > issue a
> > > STARTTLS command first a29sm294756qbd
> > > 
> > > --- 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
> > > bindingFlags,
> > > Binder binder, Object target, Object[] providedArgs,
> > > ParameterModifier[]
> > > modifiers, CultureInfo culture, String[] namedParams)
> > > at
> System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object
> > > obj,
> > > String methodName, Object[] args)
> > > --- End of inner exception stack trace ---
> > > at
> System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object
> > > obj,
> > > String methodName, Object[] args)
> > > at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage
> message)
> > > at System.Web.Mail.SmtpMail.Send(MailMessage message)
> > > at log4net.Appender.SmtpAppender.SendBuffer(LoggingEvent[]
> events)
> > > 
> > >  
> > > 
> > > Have I missed something in my configuration? When I send e-mail
> > with
> > > System.Net.Mail.SmtpClient.Send(.) with the setting provided
> above,
> > > everything goes ok.
> > > 
> > >  
> > > 
> > >  
> > > 
> > > Best regards,
> > > 
> > > Vladimir Kovalenko
> > > 
> > >  
> > > 
> > >  
> > > 
> > > 
> > 
> > 
> 
> 


Mime
View raw message