I use ClientApiService from Sitecore 9.1 to send e-mails programmatically and I don't use custom facests to store custom token information.
I have automated message based on web item with usage of custom token $my-html$
This is my code:
public IClientApiService ClientApiService { get; }
public ClientSamples(IClientApiService clientApiService)
{
ClientApiService = clientApiService;
}
public void SendAutomatedExample(Guid messageId, ContactIdentifier identifier, object htmlContent)
{
var messageOpitons = new AutomatedMessage();
messageOpitons.MessageId = messageId;
messageOpitons.ContactIdentifier = identifier;
messageOpitons.CustomTokens = new Dictionary<string, object> { {"my-html", htmlContent} };
ClientApiService.SendAutomatedMessage(messageOpitons);
}
When I pass string
as htmlContent service.SendAutomatedExample(someId, someidentifier, "<span>test</span>")
, then Contact get correct email which has replaced $my-html$. But it has plain text and not html.
When I pass MvcHtmlString
as htmlContent service.SendAutomatedExample(someId, someidentifier, new MvcHtmlString("<span>test</span>"))
, then Contact get email with $my-html$ replaced by {}.
Additional information: I need to render some dynamic html table as custom token I am not able to use custom facests for this scenario