【发布时间】:2017-10-05 05:12:21
【问题描述】:
如何在 c# 中使用 sendgrid 电子邮件中的替换向多个recipents 发送电子邮件? Sendgrid api 替换不适用于多个接收者。 我正在使用 Sendgrid 发送带有包含多个变量的模板的电子邮件。当我的电子邮件只有一个收件人时,一切正常。
当我在 To 或 To 中有多个收件人以及在 Cc 中有多个收件人时,第一封电子邮件是可以的,但以下邮件的替换标签中有空字符串。
下面是我的代码:
var message = new SendGridMessage();
message.Subject = fullName + " has shared SmartForm with you for " + PLConstants.APP_NAME;
message.EnableTemplateEngine(PLConstants.SEND_SMARTFORM_EMAIL_TOUSER);
if (!string.IsNullOrEmpty(emailIds))
{
string[] bccAddressField = emailIds.Split(',');
for (int icount = 0; icount < bccAddressField.Length; icount++)
{
if (bccAddressField[icount].ToString() != "")
{
if (message.To.Length == 0)
{
message.AddTo(bccAddressField[icount].ToString());
}
else
{
//message.AddTo(bccAddressField[icount].ToString());
message.AddBcc(new EmailAddress(bccAddressField[icount].ToString()).ToString());
}
}
}
}
string profileUrl = string.Format("{0}{1}", PLConstants.SMARTLINK_URL,(HttpContext.Current.Session[PLConstants.SESSION_USERNAME].ToString()));
message.AddSubstitution("{SenderName}",new List<string> { (HttpContext.Current.Session[PLConstants.SESSION_FIRST_NAME].ToString()) });
message.AddSubstitution("{SmartListingName}", new List<string> { objSmartListingModel.Title });
message.AddSubstitution("{SmartListingLink}", new List<string> { smartListingLink });
message.AddSubstitution("{SmartListingRedirectionLink}", new List<string> { smartListingRedirectionLink });
message.Html = " ";
Mailer.SendEmail(message);
【问题讨论】:
-
您是否使用 V3 api 发送电子邮件?什么是
Mailer.SendEmail(message);这不是发送邮件的正确方式 -
其实“Mailer”是我的班级,我维护了所有的邮件发送功能,“SendEmail”就是其中之一。
-
你能发布Mailer类吗?
-
感谢您的回复。现在我根据我上次的回答找到了解决方案。