邮件合并sendgrid c#

时间:2017-05-01 16:24:24

标签: c# sendgrid

使用SendGrid C# API。我花了几个小时查看文档here,更令人沮丧{{​​3}}。我已经搜索了几个SO帖子并乱用了代码,但无济于事。

基本上我有一个电子邮件模板,就像这样开始:

--------------------------
{RecipientName},

here is the rest of the email body...
--------------------------------

我只想让{RecipientName}的每个实例成为接收电子邮件的人的第一个名字。我看到有一个Personalization类,但似乎没有任何文档或实际示例如何将它用于此目的。

以下代码适用于将电子邮件实际发送给收件人:

List<EmailAddress> allRecipients = new List<EmailAddress>();
for (int i = 0; i < notice.AllRecipients.Count; i++)
{
     _Logger.Info("processing recipient number " + i);
     Employee e = _companyLogic.GetEmployeeByEmployeeId(notice.AllRecipients[i].EmployeeId);
     EmailAddress email = new EmailAddress(e.EmailAddress, e.FirstName + " " + e.LastName);
     allRecipients.Add(email);
}

msg.AddTos(allRecipients);

这似乎是添加替换的最佳位置将在for循环中。但我不知道如何实现这一目标。

1 个答案:

答案 0 :(得分:0)