//the main func to send email to approvers public void SendAlertToApprovers() { DataTable dt = TAform.GetData(); string userids = string.Empty; if (dt.Rows.Count > 0) { //先拼接成字符串 foreach (DataRow dr in dt.Rows) { userids += dr[0]; } userids = userids.Replace("PP", "P"); List<string> list = new List<string>(); //筛选出userid string[] strUser = userids.Split('P'); for (int i = 0; i < strUser.Length; i++) { if (!list.Contains(strUser[i])) { list.Add(strUser[i]); } } string strBody = string.Empty; string strTitle = ConfigurationManager.AppSettings["EmailAlert.Subject"]; string strFrom = ConfigurationManager.AppSettings["EmailAlert.SendFrom"]; string strEmailUser = ConfigurationManager.AppSettings["EmailAlert.EmailUser"]; string pid = ConfigurationManager.AppSettings["EmailAlert.EmailPwd"]; string strServer = ConfigurationManager.AppSettings["EmailAlert.EmailServer"]; int EmptyCount = 0; //根据userid发送邮件 Email.EmailHistoryDataTable tbHistory = new Email.EmailHistoryDataTable(); Email.EmailHistoryRow row; for (int n = 0; n < list.Count; n++) { if (string.IsNullOrEmpty(list[n])) { EmptyCount++; continue; } else { string strAddress = TAstuff.GetDataByID(int.Parse(list[n]))[0].EMail; strBody = GetBody(list[n]); row = tbHistory.NewEmailHistoryRow(); row.SentTo = strAddress; row.EmailContent = strBody; row.SendDate = DateTime.Now; row.Result = "Success " + n + "of" + list.Count + ", Empty:EmptyCount"; row.ResultType = 1; try { Utility.SendMail(strAddress, "", strTitle, strBody, strFrom, strEmailUser, pid, strServer); } catch (Exception e) { row.Result = "Failed:" + e.ToString(); row.ResultType = 0; throw e; } tbHistory.AddEmailHistoryRow(row); this.TAHisotry.Update(row); } } this.TAHisotry.Update(tbHistory); } }
//the main func to send email to approvers public void SendAlertToApprovers() { DataTable dt = TAform.GetData(); string userids = string.Empty; if (dt.Rows.Count > 0) { //先拼接成字符串 foreach (DataRow dr in dt.Rows) { userids += dr[0]; } userids = userids.Replace("PP", "P"); List <string> list = new List <string>(); //筛选出userid string[] strUser = userids.Split('P'); for (int i = 0; i < strUser.Length; i++) { if (!list.Contains(strUser[i])) { list.Add(strUser[i]); } } string strBody = string.Empty; string strTitle = ConfigurationManager.AppSettings["EmailAlert.Subject"]; string strFrom = ConfigurationManager.AppSettings["EmailAlert.SendFrom"]; string strEmailUser = ConfigurationManager.AppSettings["EmailAlert.EmailUser"]; string pid = ConfigurationManager.AppSettings["EmailAlert.EmailPwd"]; string strServer = ConfigurationManager.AppSettings["EmailAlert.EmailServer"]; int EmptyCount = 0; //根据userid发送邮件 Email.EmailHistoryDataTable tbHistory = new Email.EmailHistoryDataTable(); Email.EmailHistoryRow row; for (int n = 0; n < list.Count; n++) { if (string.IsNullOrEmpty(list[n])) { EmptyCount++; continue; } else { string strAddress = TAstuff.GetDataByID(int.Parse(list[n]))[0].EMail; strBody = GetBody(list[n]); row = tbHistory.NewEmailHistoryRow(); row.SentTo = strAddress; row.EmailContent = strBody; row.SendDate = DateTime.Now; row.Result = "Success " + n + "of" + list.Count + ", Empty:EmptyCount"; row.ResultType = 1; try { Utility.SendMail(strAddress, "", strTitle, strBody, strFrom, strEmailUser, pid, strServer); } catch (Exception e) { row.Result = "Failed:" + e.ToString(); row.ResultType = 0; throw e; } tbHistory.AddEmailHistoryRow(row); this.TAHisotry.Update(row); } } this.TAHisotry.Update(tbHistory); } }