c# - Sending Email from Rows in GridView -


i have scenario in which, i've done work further process need help.

i've excelsheet imported grid view , suppose there 10 records in it. i've send email , email retrieved gridview want @ first email send first 5 records after taking 5 seconds email resend next 5 records.

following email sending code:

void send_mail()     {         try         {             string pass, fromemailid, hostadd;             foreach (gridviewrow gr in datagridview.rows)             {                 hostadd = configurationmanager.appsettings["host"].tostring();                 fromemailid = configurationmanager.appsettings["frommail"].tostring();                 pass = configurationmanager.appsettings["password"].tostring();                  label lblname = gr.findcontrol("lblname") label;                 label lblmail = gr.findcontrol("lblemail") label;                  string name = lblname.text;                 string mail = lblmail.text;                 string subject = txtsubject.text;                  smtpclient client = new smtpclient();                 mailmessage msg = new mailmessage();                  networkcredential credentials = new networkcredential(fromemailid, pass);                  client.host = hostadd;                 client.port = 25;                 client.usedefaultcredentials = false;                 client.credentials = credentials;                 client.enablessl = true;                 mailaddress = new mailaddress(fromemailid);                 msg.isbodyhtml = true;                 msg.subject = subject;                 msg.body = readtemplate(name);                 msg.to.add(mail);                 msg.from = from;                 client.send(msg);                 lblmessage.text = "email send successfully";                 lblmessage.visible = true;             }         }          catch (exception ex)         {             lblmessage.text = ex.message;             lblmessage.visible = true;         }     } 

take count of iteration (or use for instead of foreach) , when reach fifth iteration put thread.sleep(5000);

something that:

int counter = 0; foreach (gridviewrow gr in datagridview.rows) {     if (counter > 0 && counter % 5.0 == 0)     {         thread.sleep(5000);     }  //more stuff sending mail...     counter++; } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -