0

我需要在外发电子邮件中添加以下标签:

{"X-MC-模板", "testheader"}

我目前用来发送电子邮件的代码是:

var header = new[]{"X-MC-Tags:test"};
try {
    // Send email
    WebMail.Send(to: customerEmail,
        subject: "Test Subject",
        body: customerRequest,
        additionalHeaders: header
    );
}

谢谢,加文

4

1 回答 1

1

Send 方法接受一个IEnumerable<string>表示附加的标头。

http://msdn.microsoft.com/en-us/library/hh414138(v=vs.111).aspx

每个字符串的格式必须为“header:value”,例如

var customHeader = new[]{"X-MC-Tags:gavin"};

将标头编织到 MailMessage 中的代码查找冒号作为分隔符。这是 WebMail 帮助程序使用的内部 TryParseHeader 方法:

internal static bool TryParseHeader(string header, out string key, out string value)
{
    int pos = header.IndexOf(':');
    if (pos > 0)
    {
        key = header.Substring(0, pos).TrimEnd();
        value = header.Substring(pos + 1).TrimStart();
        return key.Length > 0 && value.Length > 0;
    }
    key = null;
    value = null;
    return false;
}
于 2013-04-18T06:05:06.820 回答