gpt4 book ai didi

c# - 如何在nlog中发送彩色邮件

转载 作者:行者123 更新时间:2023-11-30 12:40:27 25 4
gpt4 key购买 nike

配置下面是我的nlog设置,这个设置发送邮件就可以了。

<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>

但我想发送彩色邮件。如何设置配置?

最佳答案

对于电子邮件中的颜色标记,您需要 html 邮件和 CSS 样式。

例如这个 html:

<body>
<b style="color:red">Bold and red text</b>
</body>

您需要将邮件目标上的 html 选项设置为 true 并且在您的 nlog.config 中您需要对 html 进行 XML 编码,因此结果:

<target name="mail" xsi:type="Mail"
html="true"
...

body="&lt;body&gt;
&lt;b style=&quot;color:red&quot;&gt;Bold and red text&lt;/b&gt;
&lt;/body&gt;"
/>

请注意,并非所有电子邮件客户端都支持所有 CSS。参见 CSS Support Guide for Email Clients

关于c# - 如何在nlog中发送彩色邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41800501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com