我正在使用C#,4.7.1 FW和SendGrid nuget。
我已经与SG支持部门联系,到目前为止,尚未定向或弄清楚如何发送模板。我尝试使用本机MailMessage以及SendGridMessage。
我指定了我的模板ID,但我仍然遇到电子邮件无法发送的问题,并被告知“动态模板可能无法使用替代”
这是我正在用砖墙nip头的最新片段:
var apiKey = "snip";
var client = new SendGridClient(apiKey);
var from = new EmailAddress("from@domain.com", "display name");
var subject = "Sending an email template";
var to = new EmailAddress("me@domain.com", "To Name");
var plainTextContent = "";
var htmlContent = ""; // I read htmlContent needs to be blank?
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
Personalization p = new Personalization
{
Substitutions = new Dictionary<string, string>()
};
p.Substitutions.Add("[eventname]", "test event"); // my template has 3 subs, this is one of them
p.Tos = new List<EmailAddress>();
p.Tos.Add(to);
msg.Personalizations.Add(p);
msg.SetTemplateId("snip");
var response = await client.SendEmailAsync(msg);
var stringResponse = response.Body.ReadAsStringAsync();
响应:
{“错误”:[{“消息”:“替代不能与动态模板一起使用”,“字段”:“个性化1.替代”,“帮助”:“ http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.personalizations.substitutions”}] }
我接近将所有这些还原为构建自己的HTML模板并将其存储在数据库中,将其拉出并用值替换[eventname]之类的占位符。这不应该那么难。