log4net SmtpAppender stepped pit summary

Errors collection:

System.Net.Mail.SmtpException: command sequence is incorrect. The server response was: Error: need EHLO and AUTH first!

System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: can not read data from the transport connection: net_io_connectionclosed.

 

 

After reading SmtpAppender source code and repeated testing comparison found that the lack of  authentication configuration, including values (None, Basic (need ID and password), Ntlm), mail servers now support SSL, so it needs to pay attention to configure the port number of

 

Send e-mail as an example Tencent

  <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
    <to value="目标邮件@xxx.com" />
    <from value="发送邮件@xxx.com" />
    <username value="发送邮件@xxx.com"/>
    <subject value="主体" />
    <password value="密码"/>
    <authentication value="Basic" />
    <smtpHost value="smtp.exmail.qq.com" />
    <bufferSize value="512" />
    <lossy value="true" />
    <enableSsl value="true" />
    <port value="587"/>
    <evaluator type="log4net.Core.LevelEvaluator">
      <threshold value="WARN"/>
    </evaluator>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
    </layout>
  </appender>

 Note plus red font configuration

 

Guess you like

Origin www.cnblogs.com/smartstar/p/11588937.html