我正在尝试通过Sendgrid api发送电子邮件,但出现此错误:
{“错误”:[{”消息”:“动态替换不能使用 模板“,”字段“:”个性化.0。替换“,”帮助“:” http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.personalizations.substitutions“}]}
我正在使用的代码是这样的:
var sendGridMessageWithTemplate = new SendGridMessage();
sendGridMessageWithTemplate.From = new EmailAddress("donotreply@mydomain.com");
Personalization personalization = new Personalization();
var substitions = new System.Collections.Generic.Dictionary<string, string>();
substitions.Add("-recipientCompanyName-", "test company name");
personalization.Tos = new System.Collections.Generic.List<EmailAddress>();
personalization.Tos.Add(new EmailAddress("someemail@gmail.com"));
sendGridMessageWithTemplate.Personalizations = new List<Personalization>();
sendGridMessageWithTemplate.Personalizations.Add(personalization);
sendGridMessageWithTemplate.AddSubstitutions(substitions);
sendGridMessageWithTemplate.TemplateId = "d-mytemplateid";
var result = mailService.SendAsync(sendGridMessageWithTemplate).Result;
您知道我在做什么错吗,如何替换模板中的令牌?