当 SmtpClient 工作时,SmtpAppender 无法通过 smtp-server 发送电子邮件
SmtpAppender fails sending Emails through smtp-server while SmtpClient works
我尝试在 LogNet 中使用 SmtpAppender:
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="user1@company.com,user2@company.com" />
<from value="noreply@company.com" />
<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>
当我在 Log4net 中启用调试日志记录时,我收到以下错误:
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)
不过。当我尝试从使用此 log4net 配置的程序中通过同一 SMTP 服务器发送邮件时:
MailMessage msg = new MailMessage(sender, recipients, subject, body);
mtpClient client = new SmtpClient("smtp.company.com", 25);
client.Send(msg);
一切正常。所以这不可能是一个简单的 SMTP-Server/FireWall-Issue.
SMTPAppender 的工作方式是否与可能导致此问题的 .NET 标准 StmpClient.Send() 不同?
@Bob Geiger 指出了正确的方向,Log4net 似乎使用了完全相同的机制。
事实证明这是一个 Virusscan/Spam-Protection 问题。仅定义允许通过我们的 smtp 服务器发送邮件的应用程序。虽然我们中的一个程序使用与 log4net 相同的后端 - 应用程序使用不同的文件名,因此可以发送邮件,而另一个程序则不能。
我们必须在病毒扫描配置中允许特定的 .exe 文件。
我尝试在 LogNet 中使用 SmtpAppender:
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="user1@company.com,user2@company.com" />
<from value="noreply@company.com" />
<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>
当我在 Log4net 中启用调试日志记录时,我收到以下错误:
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)
不过。当我尝试从使用此 log4net 配置的程序中通过同一 SMTP 服务器发送邮件时:
MailMessage msg = new MailMessage(sender, recipients, subject, body);
mtpClient client = new SmtpClient("smtp.company.com", 25);
client.Send(msg);
一切正常。所以这不可能是一个简单的 SMTP-Server/FireWall-Issue.
SMTPAppender 的工作方式是否与可能导致此问题的 .NET 标准 StmpClient.Send() 不同?
@Bob Geiger 指出了正确的方向,Log4net 似乎使用了完全相同的机制。
事实证明这是一个 Virusscan/Spam-Protection 问题。仅定义允许通过我们的 smtp 服务器发送邮件的应用程序。虽然我们中的一个程序使用与 log4net 相同的后端 - 应用程序使用不同的文件名,因此可以发送邮件,而另一个程序则不能。
我们必须在病毒扫描配置中允许特定的 .exe 文件。