Mail target
通过SMTP协议发送Email信息
语法
<targets> <target xsi:type="Mail" name="String" header="Layout" footer="Layout" layout="Layout" html="Boolean" addNewLines="Boolean" replaceNewlineWithBrTagInHtml="Boolean" encoding="Encoding" subject="Layout" to="Layout" bcc="Layout" cc="Layout" from="Layout" body="Layout" smtpUserName="Layout" enableSsl="Boolean" smtpPassword="Layout" smtpAuthentication="Enum" smtpServer="Layout" smtpPort="Integer" useSystemNetMailSettings="Boolean" timeout="Integer" /></targets> |
参数
一般配置
name - target的名称
布局配置
header - 信息页头
footer - 信息页尾
layout - 输出文本格式。默认: ${longdate}|${level:uppercase=true}|${logger}|${message}
html - 是否将发送的信息转换为html格式,而不是纯文本。默认:False
addNewLines - 是否在每次输出信息之间,加一个空行
replaceNewlineWithBrTagInHtml - 是否把输出文本中的换行符替换为<br/>。默认:False
encoding - 输出日志的文本格式。默认: UTF-8
信息配置
subject - 邮件标题。默认: ${machinename}
to - 发送的邮件地址,多个用分号分隔 (e.g.john@domain.com;jane@domain.com)。
bcc - 密送的邮件地址, 多个用分号分隔(e.g.john@domain.com;jane@domain.com)。
cc - 抄送的邮件地址, 多个用分号分隔 (e.g.john@domain.com;jane@domain.com)。
from - 发送者地址 (e.g. joe@domain.com)。
body - 邮件正文(repeated for each log message send in one mail)。默认:${message}
SMTP 配置
smtpUserName - 连接SMTP服务器的用户名(当SmtpAuthentication配置为"basic"时有效)。
enableSsl - 是否启用SSL。默认False
这个参数在下面情况不被支持
- NLog v1.0 for .NET Framework 1.0
- NLog v1.0 for .NET Framework 1.1
- NLog v1.0 for .NET Framework 2.0
smtpPassword - 连接SMTP服务器的密码 (当SmtpAuthentication配置为"basic"时有效)。
smtpAuthentication - SMTP服务器验证模式
可能的值:
- Basic - 基础方式(用户名和用户密码)
- None - 不需要验证
- Ntlm - NTLM 验证
smtpServer - SMTP 服务器地址
smtpPort - SMTP服务器端口。默认: 25
useSystemNetMailSettings - 从 system.net/mailSettings获取配置。 默认: False
timeout - SMTP客户端超时时间。默认: 10000
备注
应用程序配置文件
如果应用程序的配置文件包含了邮件配置
<system.net> <mailSettings> <smtp from="mail@domain.com" deliveryMethod="SpecifiedPickupDirectory"> <network host="localhost" port="25"/> <specifiedPickupDirectory pickupDirectoryLocation="C:/Temp/Email"/> </smtp> </mailSettings></system.net> |
如果target没有重新配置,这个值将被使用。
邮件地址格式
你能够使用下面的邮件地址格式:
"John Doe <john.doe@example.com>"
但是,如果有特殊字符 < and > ,则必须转译。John Doe会被转移为: <john.doe@example.com>
浙公网安备 33010602011771号