The problem is that the subject isn't sent as Html, it's sent as clear text (at least I think this is always true).
An idea might be to remove the HtmlEncode from the MessageTokenProvieder and then just do this in the Tokenizer:
public string Replace(string template, IEnumerable<Token> tokens, bool htmlEncode)
{
if (string.IsNullOrWhiteSpace(template))
throw new ArgumentNullException("template");
if (tokens == null)
throw new ArgumentNullException("tokens");
foreach (var token in tokens)
{
string tokenValue = token.Value;
if(htmlEncode)
tokenValue = HttpUtility.HtmlEncode(tokenValue);
template = Replace(template, String.Format(@"%{0}%", token.Key), tokenValue);
}
return template;
}
And then in WorkflowMessageService in SendNotification
private int SendNotification(MessageTemplate messageTemplate,
EmailAccount emailAccount, int languageId, IEnumerable<Token> tokens,
string toEmailAddress, string toName)
{
//retrieve localized message template data
var bcc = messageTemplate.GetLocalized((mt) => mt.BccEmailAddresses, languageId);
var subject = messageTemplate.GetLocalized((mt) => mt.Subject, languageId);
var body = messageTemplate.GetLocalized((mt) => mt.Body, languageId);
//Replace subject and body tokens
var subjectReplaced = _tokenizer.Replace(subject, tokens, false);
var bodyReplaced = _tokenizer.Replace(body, tokens, true);
var email = new QueuedEmail()
{
Priority = 5,
From = emailAccount.Email,
FromName = emailAccount.DisplayName,
To = toEmailAddress,
ToName = toName,
CC = string.Empty,
Bcc = bcc,
Subject = subjectReplaced,
Body = bodyReplaced,
CreatedOnUtc = DateTime.UtcNow,
EmailAccountId = emailAccount.Id
};
_queuedEmailService.InsertQueuedEmail(email);
return email.Id;
}