//Actual location where email is sent. Currently no parameters because they are based on the day. Should move to it's own helper folder at some point. public void SendEmail() { List <string> ProcessedNotificationEmails = ConfigurationManager.AppSettings["EmailNotificationList"].Split(';').ToList(); List <string> ProcessedWinningEmails = ConfigurationManager.AppSettings["EmailWinnerList"].Split(';').ToList(); string WinningEmailText = ConfigurationManager.AppSettings["EmailWinnerList"].ToString(); string NotificationEmailText = ConfigurationManager.AppSettings["EmailWinnerList"].ToString(); try { Sendmail.SendMail($"Fuel Purchasing Fuel Price for Today", "Today's Fuel Price", NotificationEmailText, "AS1", to: ProcessedNotificationEmails); Sendmail.SendMail($"Fuel Purchasing Winner for Today", "Winning Fuel Bid", WinningEmailText, "AS1", to: ProcessedWinningEmails); } catch (Exception e) { throw; } }
private static void EmailNormal(Dictionary <string, object> valueList, DTO.LIST_TASKInfo infTask) { ReportGenerator rgAtt = null; ReportGenerator rgCnt = null; if (infTask.AttQD_ID != "") { QueryBuilder.SQLBuilder sqlBuiderA = QueryBuilder.SQLBuilder.LoadSQLBuilderFromDataBase(infTask.AttQD_ID, _db, ""); rgAtt = new ReportGenerator(sqlBuiderA, infTask.AttQD_ID, "", _repConnect, _tempPath, _reptPath, __documentDirectory); } else { DataSet ds = new DataSet(); rgAtt = new ReportGenerator(ds, infTask.AttTmp, _db, _reptPath, _tempPath, _reptPath, __documentDirectory); } if (infTask.CntQD_ID != "") { QueryBuilder.SQLBuilder sqlBuiderC = QueryBuilder.SQLBuilder.LoadSQLBuilderFromDataBase(infTask.CntQD_ID, _db, ""); rgCnt = new ReportGenerator(sqlBuiderC, infTask.CntQD_ID, "", _repConnect, _tempPath, _reptPath, __documentDirectory); } else { DataSet ds = new DataSet(); rgCnt = new ReportGenerator(ds, infTask.CntTmp, _db, _repConnect, _tempPath, _reptPath, __documentDirectory); } rgAtt.ValueList = valueList; rgCnt.ValueList = valueList; ExcelFile xls = rgAtt.CreateReport(); rgAtt.UserID = _userID; rgCnt.Close(); bool flagRun = false; string[] arrVRange = infTask.ValidRange.Split(';'); if (arrVRange.Length >= 1) { for (int i = 1; i <= xls.SheetCount; i++) { TXlsNamedRange range = xls.GetNamedRange(arrVRange[0], 0); if (range != null) { xls.ActiveSheet = range.SheetIndex; object flag = xls.GetCellValue(range.Top, range.Left); if (flag != null && !String.IsNullOrEmpty(flag.ToString().Trim()) && flag.ToString().Trim() != "0") { flagRun = true; break; } } } } string title = infTask.Description; if (flagRun) { try { using (TextWriter wt = rgCnt.ExportHTML(_reptPath)) { ExcelFile xls1 = rgCnt.XlsFile; if (arrVRange.Length >= 2) { for (int i = 1; i <= xls1.SheetCount; i++) { TXlsNamedRange range = xls1.GetNamedRange(arrVRange[1], 0); if (range != null) { xls1.ActiveSheet = range.SheetIndex; object flag = xls1.GetCellValue(range.Top, range.Left); if (flag != null && !String.IsNullOrEmpty(flag.ToString())) { title = flag.ToString(); break; } } } } string content = wt.ToString(); string filename = rgAtt.ExportExcelToFile(_reptPath, infTask.Description + ".xls"); Sendmail sendMail = new Sendmail(infTask.UserID, infTask.Password, infTask.Server, infTask.Protocol, Convert.ToInt32(infTask.Port)); string[] emails = infTask.Emails.Split(','); Dictionary <string, string> arrayMail = new Dictionary <string, string>(); for (int i = 0; i < emails.Length; i++) { Match name = Regex.Match(emails[i], "\".+\""); Match mail = Regex.Match(emails[i], "<.+>"); arrayMail.Add(mail.Value.Substring(1, mail.Value.Length - 2), name.Value.Substring(1, name.Value.Length - 2)); } sErr = sendMail.SendMail(title, content, arrayMail, filename, true, true); } } catch (Exception ex) { sErr = ex.Message; } } }
protected void btSend_Click(object sender, EventArgs e) { if (Page.IsValid) { if (txtUsername.Text.Trim() == "") { Lab_message.Text = "Đăng nhập tên người dùng !"; return; } if (txtEmail.Text.Trim() == "") { Lab_message.Text = " Nhập địa chỉ thư điện tử!"; return; } Member member = new Member(); DataRow vDr = member.getUsers_Login(txtUsername.Text.Trim()); if (vDr == null) { Lab_message.Text = "Tên người dùng không tồn tại !"; return; } string vMail = vDr["email"].ToString(); if (vMail != txtEmail.Text.Trim()) { Lab_message.Text = "Email nhập không đúng !"; return; } if (vDr != null) { // Lay Radom Password qua System string vnewpass = System.Guid.NewGuid().ToString(); vnewpass = vnewpass.Replace("-", string.Empty); vnewpass = vnewpass.Substring(0, 6); Sendmail sMail = null; string NewPass = FormsAuthentication.HashPasswordForStoringInConfigFile(vnewpass.Trim(), "MD5"); try { string sMailContact = string.Empty; sMail = new Sendmail(); sMailContact = Globals.MailMaster; sMail.SmtpServer = Globals.MailServer; sMail.SmtpMailFrom = Globals.Gmail; sMail.SmtpUser = Globals.Gmail.Replace("@gmail.com", ""); sMail.SmtpPassword = Globals.GmailPassword;; sMail.SmtpPort = Convert.ToInt32(Globals.MailPort); string sContent = "<font color=#000099>Dùng thông tin sau để đăng nhập vào hệ thống: <B>Administrator</B>." + "<br> Tên người dùng (Username):<font color=red> " + txtUsername.Text.Trim() + "</font>" + "<br> Mật khẩu mới (New password):<font color=red> " + vnewpass + "</font>" + "<br> Sau khi đăng nhập hãy <B>đổi mật khẩu mới</B> để đảm bảo tính bảo mật của hệ thống ." + "<br> Xin chân thành cảm ơn ! </font>"; sMail.SendMail(sMailContact, "Bạn đã thay đổi mật khẩu thành công", sContent, true); Lab_message.Text = "Gửi thành công. Hãy đọc email để lấy thông tin ! "; } catch (Exception ex) { string s = ex.Message.ToString(); Lab_message.Text = "Không gửi được. Xem lại địa chỉ Email ! "; return; } // Update PassNew to database string vID = vDr["ID"].ToString(); member.update_Pass(vID, NewPass.Trim()); txtUsername.Text = ""; txtEmail.Text = ""; } } }