I'm using nuget package Postal for sending emails in both html and text formats. For that, there is an email header file (holding "from" and "to" info). Adding X-Entity-Ref-ID: HeaderId
, where HeaderId is a guid, to this file (before the From:
and To:
parameters) works. Give a unique reference value to X-Entity-Ref-ID, rather than no value.
You may well not be using Postal but this approach may work for other packages as well.
In the Controller:
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();
and then, in the email header file:
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
with the EmailModel defined as:
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 ..
}