public static void SendEXMEmail()
{
// 发送人的名称
var toUserName = "Abigail";
// 发送人的邮件
var toEmail = "[email protected]";
// 发送的内容
string emailBody = "Hello, World.";
// 需要发送的数据 dict,后续可通过 dict 的 keys 来替换 Message Item 内部的 placeholder.
var tokens = new Dictionary<string, object>
{
{ "name", toUserName },
{ "EmailAddress", toEmail },
{ "EmailBody", emailBody },
{ "date", "" }
};
// 标识符,随意填写一个
string source = "form";
// Message Template: /sitecore/templates/System/Email/Messages/HTML Message
// Message Item 的 ID
Guid messageId = Guid.Empty;
// 指定发送 language
Language language = Language.Parse("en");
// 填写邮件信息
AutomatedMessage automatedMessage = new AutomatedMessage()
{
ContactIdentifier = new ContactIdentifier(source, toEmail, ContactIdentifierType.Known),
MessageId = messageId,
CustomTokens = tokens,
TargetLanguage = language.Name,
};
// 获取总线并发送邮件
IMessageBus<AutomatedMessagesBus> automatedMessageBus = ServiceLocator.ServiceProvider.GetService<IMessageBus<AutomatedMessagesBus>>();
automatedMessageBus.Send(automatedMessage);
}
标签:language,发送,Sitecore,new,Message,AutomatedMessage,邮件
From: https://www.cnblogs.com/fires/p/18080107