【问题标题】:How to send emails with List<string>() using Send Grid mvc azure如何使用 Send Grid mvc azure 通过 List<string>() 发送电子邮件
【发布时间】:2016-01-06 00:26:06
【问题描述】:

我正在阅读 Send Grid 文档,并在其下方指出要添加收件人的电子邮件,这是必需的:

    // Add multiple addresses to the To field.
List<String> recipients = new List<String>
{
    @"Jeff Smith <jeff@example.com>",
    @"Anna Lidman <anna@example.com>",
    @"Peter Saddow <peter@example.com>"
};

myMessage.AddTo(recipients);

同时,在我的代码中,我有一个包含存储电子邮件的列表字符串。

 emailing.find_email_send = new List<string>();
 emailing.find_email_send.Add("nick@hotmail.com");
 emailing.find_email_send.Add("John@hotmail.com");
 emailing.find_email_send.Add("Jack@hotmail.com");

如何将其添加到收件人?我尝试使用 forloop:

recipients.Add(emailing.find_email_send[i]);

但似乎不起作用。

【问题讨论】:

    标签: c# asp.net-mvc email azure sendgrid


    【解决方案1】:

    如果 myMessage.AddTo 方法将 List 作为参数,并且您的地址已经在 List 中,那么您无需执行任何操作,除了:

    myMessage.AddTo(emailing.find_email_send);
    

    如果您真的想将列表中的地址添加到收件人列表中,可以:

    var recipients = new List<string>();
    foreach (var address in emailing.find_email_send)
    {
        recipients.Add(address);
    }
    

    【讨论】:

    • 嗨,大卫,感谢您的帮助。只有一件事,我是否必须将我的列表参数设置为:“”或“nick@hotmail.com”
    猜你喜欢
    • 2015-02-25
    • 2017-11-01
    • 1970-01-01
    • 2017-06-05
    • 2022-12-03
    • 2014-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多