below config was my nlog setting, this setting send mail is OK .
<target name="mail" xsi:type="Mail"
smtpServer="SMTP SERVER"
smtpPort="25"
smtpAuthentication="None"
enableSsl="false"
from="email address"
to="email address"
html="true"
encoding="UTF-8"
addNewLines="true"
replaceNewlineWithBrTagInHtml ="true"
subject="SYSTEM MESSAGE:${machinename} 於 ${shortdate} ${time} create ${level} message "
header="========================================================================="
body="${newline}
time:${longdate} ${newline}${newline}
Log level:${level:uppercase=true} ${newline}${newline}
Logger:${logger} ${newline}${newline}
Source:${callsite:className=true} ${newline}${newline}
Exception:${exception:format=type} ${newline}${newline}
Error message:${message} ${newline}${newline}"
footer="========================================================================="
/>
</targets>
<rules>
<logger name="*" minlevel="Fatal" writeTo="mail" />
</rules>
but I want to send colorful mail. How to setting configure ?
For markup like colors in your e-mail, you need a html mail and CSS styling.
e.g. this html:
<body>
<b style="color:red">Bold and red text</b>
</body>
You need to set the html
option on the mail target to true
and in your nlog.config you need to XML encode the html, so in result:
<target name="mail" xsi:type="Mail"
html="true"
...
body="<body>
<b style="color:red">Bold and red text</b>
</body>"
/>
Please note that not all CSS is supported in all email clients. See CSS Support Guide for Email Clients
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With