I try to use the SmtpAppender in LogNet:
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="[email protected],[email protected]" />
<from value="[email protected]" />
<subject value="Error" />
<smtpHost value="smtp.company.com" />
<bufferSize value="512" />
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="DEBUG"/>
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
</layout>
</appender>
When I enable debug logging in Log4net I receive the following error:
log4net:ERROR [SmtpAppender] ErrorCode: GenericFailure. Error occurred while sending e-mail notification. System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions (IP from SMTP-Server):25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address,Socket& abortSocket, Socket& abortSocket6) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at log4net.Appender.SmtpAppender.SendEmail(String messageBody) at log4net.Appender.SmtpAppender.SendBuffer(LoggingEvent[] events)
However. When I try to send a mail through the same SMTP-Server from within my program that uses this log4net-configuration:
MailMessage msg = new MailMessage(sender, recipients, subject, body);
mtpClient client = new SmtpClient("smtp.company.com", 25);
client.Send(msg);
everything works fine. So this could not be a simple SMTP-Server/FireWall-Issue.
Is the SMTPAppender working differently that the standard StmpClient.Send() from .NET that could cause this issue?