public async Task EnviarAsync(String Tabela, Int32 Empresa_id) { String TelFormat = ""; Int32 Enviados = 0; Int32 Falhas = 0; WhatsAppSendPST App; Hlp Hlp; try { App = new WhatsAppSendPST(); Con = new Connect(); Hlp = new Hlp(); EnviarOperadores(); if (cb_filtros.Checked == true) { DisplayData(App.Pesquisar(Tabela, Empresa_id, Hlp.DateFormat(dtp_inicial.Text), Hlp.DateFormat(dtp_final.Text))); } else { DisplayData(App.Pesquisar(Tabela, Empresa_id)); } for (int Cont = 0; Cont < Table.Rows.Count; Cont++) { //Controles if (Parar == true) { break; } if (Contador > 1000) { Contador = 0; } // Timer await Task.Delay(Hlp.WaitTime(Contador)); App.Destinatario = new Destinatario(); App.Destinatario.Nome = Table.Rows[Cont]["nome"].ToString(); App.Destinatario.Telefone = Hlp.TelFind(Table, Tabela, Cont); if (!String.IsNullOrEmpty(App.Destinatario.Telefone)) { TelFormat = Hlp.TelFormat(App.Destinatario.Telefone); } if (!String.IsNullOrEmpty(TelFormat)) { if (cb_testar.Checked == false) { WebReq(URL_PLATFORM, TelFormat, App.Destinatario.Nome); } else { WebReq(URL_PLATFORM, TESTE_DESTINATARIO, App.Destinatario.Nome); break; } Enviados++; lbl_enviados.Text = "ENVIADOS: " + Enviados.ToString(); lbl_total.Text = "TOTAL: " + (Enviados + Falhas).ToString(); } else { dataGridView2.Rows.Add(App.Destinatario.Nome, App.Destinatario.Telefone, "FALHA"); Falhas++; lbl_falhas.Text = "FALHAS: " + Falhas.ToString(); lbl_total.Text = "TOTAL: " + (Enviados + Falhas).ToString(); } Contador++; } lbl_enviados.Text = "ENVIADOS: " + Enviados.ToString(); lbl_falhas.Text = "FALHAS: " + Falhas.ToString(); lbl_total.Text = "TOTAL: " + (Enviados + Falhas).ToString(); MessageBox.Show("O ENVIO FOI CONCLUIDO!"); } catch (Exception e) { MessageBox.Show(e.Message); } }
public async Task EnviarAsync(String Tabela, Int32 Empresa_id) { //Condições de controle Mail = new MailMessage(); Con = new Connect(); Hlp = new Hlp(); Send = new EmailSendPST(); using (SmtpClient Smtp = new SmtpClient()) { try { Armazenar(); //Config Servidor Email Smtp.Host = Send.Host; Smtp.Port = Send.Port; Smtp.EnableSsl = true; Smtp.UseDefaultCredentials = false; Smtp.Credentials = new NetworkCredential(Send.From, Send.Pass); if (cb_filtros.Checked == true) { DisplayData(Send.Pesquisar(Tabela, Empresa_id, Hlp.DateFormat(dtp_inicial.Text), Hlp.DateFormat(dtp_final.Text))); } else { DisplayData(Send.Pesquisar(Tabela, Empresa_id)); } for (int Cont = 0; Cont < Table.Rows.Count; Cont++) { await Task.Delay(3000); Send.Destinatario = new Destinatario(); Send.Destinatario.Nome = Table.Rows[Cont]["nome"].ToString(); Send.Destinatario.Email = Table.Rows[Cont]["email"].ToString(); Send.Body = MsgFormat(); using (MailMessage Mail = new MailMessage()) { Mail.From = new MailAddress(Send.From); Mail.To.Add(new MailAddress(Send.Destinatario.Email)); //Mail.To.Add(new MailAddress("")); Mail.Subject = Send.Subject; Mail.IsBodyHtml = true; Mail.Body = Send.Body; Smtp.Send(Mail); Enviados++; lbl_enviados.Text = "ENVIADOS: " + Enviados.ToString(); lbl_total.Text = "TOTAL: " + (Enviados + Falhas).ToString(); dataGridView2.Rows.Add(Send.Destinatario.Nome, "ENVIADO", Send.Destinatario.Email); if (Parar == true) { break; } } } lbl_enviados.Text = "ENVIADOS: " + Enviados.ToString(); lbl_falhas.Text = "FALHAS: " + Falhas.ToString(); lbl_total.Text = "TOTAL: " + (Enviados + Falhas).ToString(); MessageBox.Show("ENVIO CONCLUIDO!"); } catch (Exception e) { dataGridView2.Rows.Add(Send.Destinatario.Nome, "FALHA", Send.Destinatario.Email); Falhas++; MessageBox.Show(e.Message); } } }