2016-04-15 11 views
0

大量メールリストを一度に送信できるように、一括メールリストをアドレスに追加しようとしています。これはすべてのレコードそれが私のdataset.Isからadvance.Hereでlooping.Thanksなしのアドレスリストへの総データセットを使用すると、1つのループを削除し、ちょうどこれを行うことができます私のコード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); 
+0

'ds.Tables [0] .Rows'が定数の場合、それを「受信者リスト」に入れてリストID経由で送ることができます。これにより、 "受信者リスト"管理を送信から切り離すことができます。 – Yepher

答えて

0

であることを追加するための任意のより良い方法が返されました:

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); 
} 
関連する問題