如何使用sparkpost

时间:2016-04-15 04:41:10

标签: c# sparkpost

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

 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);

1 个答案:

答案 0 :(得分:0)

你可以删除一个循环,然后执行此操作:

SyntaxError