How to set the sender name of the log4net SmtpAppender protocol in a .config file

I tried to find a solution to this minor problem for quite a while, but could not find an answer.

I want to set the sender name of my emails that I send using log4net SmtpAppender, but I cannot figure out how to do this.

This is my log4net appender configuration:

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
  <to value="sender@sending.com" />
  <from value="receiver@receiving.rom" />
  <subject value="test logging message" />
  <smtpHost value=" ... " />
  <authentication value="Basic" />
  <port value="587" />
  <bufferSize value="1" />
  <username value=" ... " />
  <password value=" ... " />
  <EnableSsl value="true"/>
  <lossy value="true" />
  <evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="FATAL"/>
  </evaluator>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
  </layout>
</appender>

It works, but when I receive the email, the senderโ€™s name is everything that comes before the @ parameter from the โ€œfromโ€ parameter, in this case the โ€œsenderโ€ (like this sender@sending.com ).

What I want is a custom name, say Notifier, but still keep sending from sender@sending.com

( , )... from_name sender_name... ...

SO, , , - :)

+4
1

SmtpAppender ( 469) new MailAddress(m_from), . , , "" MSDN.

:

Notifier <sender@sending.com>

Log4net XML:

<from value="Notifier &lt;sender@sending.com&gt;" />
+6

Source: https://habr.com/ru/post/1523275/


All Articles