我正在阅读发送网格文档,它下面指出,为了添加收件人的电子邮件,这是必需的:
// Add multiple addresses to the To field.
List<String> recipients = new List<String>
{
@"Jeff Smith <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ae0efececcaeff2ebe7fae6efa4e9e5e7" rel="noreferrer noopener nofollow">[email protected]</a>>",
@"Anna Lidman <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="88e9e6e6e9c8edf0e9e5f8e4eda6ebe7e5" rel="noreferrer noopener nofollow">[email protected]</a>>",
@"Peter Saddow <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97e7f2e3f2e5d7f2eff6fae7fbf2b9f4f8fa" rel="noreferrer noopener nofollow">[email protected]</a>>"
};
myMessage.AddTo(recipients);
同时,在我的代码中,我有一个包含存储电子邮件的列表字符串。
emailing.find_email_send = new List<string>();
emailing.find_email_send.Add("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e18f88828aa1898e958c80888dcf828e8c" rel="noreferrer noopener nofollow">[email protected]</a>");
emailing.find_email_send.Add("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a002522240a22253e272b232664292527" rel="noreferrer noopener nofollow">[email protected]</a>");
emailing.find_email_send.Add("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d09ab1b3bb90b8bfa4bdb1b9bcfeb3bfbd" rel="noreferrer noopener nofollow">[email protected]</a>");
如何将其添加到收件人?我尝试使用 forloop:
recipients.Add(emailing.find_email_send[i]);
但似乎不起作用。
最佳答案
如果 myMessage.AddTo 方法采用列表作为参数,并且您的地址已在列表中,那么您不需要执行任何操作,除了:
myMessage.AddTo(emailing.find_email_send);
如果您确实想将列表中的地址添加到收件人列表中,则:
var recipients = new List<string>();
foreach (var address in emailing.find_email_send)
{
recipients.Add(address);
}
关于c# - 如何使用 Send Grid mvc azure 通过 List<string>() 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34623687/