我正在使用 nuget 包 Postal 以 html 和文本格式发送电子邮件。为此,有一个电子邮件头文件(包含“发件人”和“收件人”信息)。将X-Entity-Ref-ID: HeaderId
HeaderId 为 guid 的位置添加到此文件(在From:
andTo:
参数之前)有效。给 X-Entity-Ref-ID 一个唯一的参考值,而不是没有值。
您可能不会使用 Postal,但这种方法也可能适用于其他包裹。
在控制器中:
var emailModel = new EmailModel()
{
To = user.UserName, // user is your User entity
// Text replacement to stop Gmail showing mailto tag
UserName = user.UserName.Replace("@", "<span>@</span>").Replace(".", "<span>.</span>"),
// HeaderId to insert a guid into X-Entity-Ref-ID header to prevent Gmail threading
HeaderId = new Guid()
};
emailModel.Send();
然后,在电子邮件头文件中:
X-Entity-Ref-ID: @Model.HeaderId // This assigns a unique value
To: @Model.To
From: ThisCo <noreply@thisco.com>
Subject: The Email Subject
Views: Text, Html
EmailModel 定义为:
public class SignupLinkEmail : Email // inheriting from the nuget Postal Email class
{
public string To { get; set; }
public string UserName { get; set; }
public Guid HeaderId { get; set; }
// other things ..
}