Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用sparkpost将电子邮件批量列表添加到从数据集返回的地址_C#_Sparkpost - Fatal编程技术网

C# 如何使用sparkpost将电子邮件批量列表添加到从数据集返回的地址

C# 如何使用sparkpost将电子邮件批量列表添加到从数据集返回的地址,c#,sparkpost,C#,Sparkpost,我正在尝试将批量邮件列表添加到地址中,以便一次发送该批量邮件列表。在这里,我通过循环到从数据集返回的每个记录中来完成此操作。是否有更好的方法将该总数据集添加到地址列表中而不循环。提前感谢。这是我的代码 DataSet ds = new DataSet(); List<string> to = new List<string>(); //I have returned one dataset containing list of emails to be send.

我正在尝试将批量邮件列表添加到地址中,以便一次发送该批量邮件列表。在这里,我通过循环到从数据集返回的每个记录中来完成此操作。是否有更好的方法将该总数据集添加到地址列表中而不循环。提前感谢。这是我的代码

 DataSet ds = new DataSet();

 List<string> to = new List<string>();

//I have returned one dataset containing list of emails to be send.

 ds = email.GetBulkProcessMails("Process");

//here I am looping through every record in the dataset and adding that records to my List

 if (ds.Tables.Count > 0)
            {

                foreach (DataRow dtrow in ds.Tables[0].Rows)
                {
                    tomailscount bmscount = new tomailscount();
                    bmscount.destinationmails = dtrow["tomail_id"].ToString();
                    to.Add(bmscount.destinationmails.ToString());
                }
            }


//Here I am assigning that entire list to address and adding that recipient for transmission
  for (int i = 0; i < to.Count; i++)
            {
                var recipient = new Recipient
                {

                    Address = new Address { Email = to[i] }

                };
                transmission.Recipients.Add(recipient);
            }


//Here I am sending that transmission

var sparky = new Client(ConfigurationManager.AppSettings["APIKey"]);
sparky.Transmissions.Send(transmission);
DataSet ds=新数据集();
列表到=新列表();
//我返回了一个包含要发送的电子邮件列表的数据集。
ds=email.getBulkProcessMail(“处理”);
//在这里,我循环遍历数据集中的每条记录,并将这些记录添加到我的列表中
如果(ds.Tables.Count>0)
{
foreach(ds.Tables[0].行中的DataRow dtrow)
{
tomailscont bmscont=新的tomailscont();
bmscont.destinationmails=dtrow[“tomail_id”].ToString();
添加(bmscont.destinationmails.ToString());
}
}
//在这里,我将整个列表分配给地址,并添加收件人以进行传输
for(int i=0;i
您可以删除一个循环,只需执行以下操作:

if (ds.Tables.Count > 0)
{

    foreach (DataRow dtrow in ds.Tables[0].Rows)
    {
        tomailscount bmscount = new tomailscount();
        bmscount.destinationmails = dtrow["tomail_id"].ToString();
        to.Add(bmscount.destinationmails.ToString());
        transmission.Recipients.Add(new Recipient {
          Address = new Address { Email = bmscount.destinationmails.ToString() }
        });
    }

    // send it
    var sparky = new Client(ConfigurationManager.AppSettings["APIKey"]);
    sparky.Transmissions.Send(transmission);
}

如果
ds.Tables[0].Rows
为常量,则可以将其放入“收件人列表”并通过列表ID发送。这将允许您将“收件人列表”管理与传输分离。