void sendEmail1(string mailtype) { bool ok = false; String sender_email = "", sender_pass = "", receiver_email = ""; DataTable dt, dt1 = new DataTable(); label6.Invoke(new Action(() => { label6.Text = "Sending reports.."; })); try { inc_pbar(10); if (mailtype == "g") { dt = db.QueryBySQLCode("SELECT email_sender,e_sender_password FROM rssys.m99"); dt1 = db.QueryBySQLCode("SELECT * FROM rssys.auto_email"); if (dt.Rows.Count > 0) { sender_email = dt.Rows[0]["email_sender"].ToString(); sender_pass = dt.Rows[0]["e_sender_password"].ToString(); if (dt1.Rows.Count > 0) { for (int i = 0; i < dt1.Rows.Count; i++) { receiver_email = dt1.Rows[i]["email"].ToString(); //lbl_notif.Text = ""; lbl_notif.Invoke(new Action(() => { lbl_notif.Text = "Sending Reports to : " + receiver_email; })); send(sender_email, sender_pass, receiver_email); lbl_notif.Invoke(new Action(() => { lbl_notif.Text = ""; disp_list(); })); } } } } else if (mailtype == "y") { inc_pbar(10); MailMessage mail = new MailMessage(); Attachment attch = new Attachment("d:/SalesOrder_01-26-2017_1_28_PM.pdf"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = "Daily Report"; mail.Body = "Ga himu ko c# app nga maka email. awa na dawat nimu sa?"; mail.Attachments.Add(attch); inc_pbar(10); using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587)) { smtp.Credentials = new NetworkCredential("*****@*****.**", "14mp455w0rd"); smtp.EnableSsl = true; try { smtp.Send(mail); ok = true; } catch (Exception ex) { ok = false; MessageBox.Show(ex.Message); } } inc_pbar(10); MessageBox.Show("Sent"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } label6.Invoke(new Action(() => { label6.Text = "done.."; })); inc_pbar(40); nextTimeToGenerate(); reset_pbar(); }
public void send_text_blast(String tbid) { String query = ""; DataTable contacts = null; DataTable address_book = null; String number = "", message = ""; int min_delay = 0; int day_delay = 0; String d_name = "", d_code = "";; Thread.Sleep(4000); try { // query = "SELECT d_cntc FROM rssys.tb_recip WHERE tbid='" + date_to_send.Rows[r]["tbid"].ToString() + "'"; query = "select * from rssys.tb_recip r LEFT JOIN rssys.tb_hdr h ON r.tbid=h.tbid LEFT JOIN rssys.tb_category c on c.tb_cat_id=h.tbtemp_id WHERE r.send_stat = 'N' AND h.tbid ='" + tbid + "'"; contacts = db.QueryBySQLCode(query); if (contacts.Rows.Count >= 0) { for (int c = 0; c < contacts.Rows.Count; c++) { tbid = contacts.Rows[c]["tbid"].ToString(); number = contacts.Rows[c]["mobile1"].ToString(); //message = date_to_send.Rows[r]["message"].ToString(); message = contacts.Rows[c]["message"].ToString(); if (contacts.Rows[c]["cat_time_delay"].ToString() != "") { min_delay = Convert.ToInt32(contacts.Rows[c]["cat_time_delay"].ToString()); } if (contacts.Rows[c]["cat_day_delay"].ToString() != "") { day_delay = Convert.ToInt32(contacts.Rows[c]["cat_day_delay"].ToString()); } d_code = contacts.Rows[c]["d_code"].ToString(); address_book = db.QueryBySQLCode("SELECT firstname,lastname,mname FROM rssys.address_book WHERE code='" + d_code + "'"); if (address_book.Rows.Count > 0) { d_name = address_book.Rows[0]["firstname"].ToString() + " " + address_book.Rows[0]["mname"].ToString() + " " + address_book.Rows[0]["lastname"].ToString(); message = "Dear " + d_name + " : " + message; } Thread.Sleep(min_delay * 60000); if (send_message(number, message)) { if (db.UpdateOnTable("tb_recip", "send_stat='Y'", "tbid='" + tbid + "' AND d_code='" + d_code + "'")) { lbl_status.Invoke(new Action(() => { lbl_status.Text = "Sending messages"; })); } } else { lbl_status.Invoke(new Action(() => { lbl_status.Text = "Func :send_text_blast => Message not sent"; })); } } } } catch (Exception ex) { lbl_status.Invoke(new Action(() => { lbl_status.Text = "Func :send_text_blast => " + ex.Message; })); } }