using System; using System.Collections.Generic; using System.Linq; using System.Text; using Quartz; using System.Data; //using NFine.Data.Extensions; using System.Configuration; using ICSSoft.FromERP; //using ICSSoft.SendMail; using System.Data.SqlClient; using System.Net; using System.Net.Mail; using System.Security.Cryptography.X509Certificates; using System.Net.Security; namespace ICSSoft.FromERP { /// /// 发送SQE人员复判 /// public class AutoSendMail_KBS : IJob { private static object key = new object(); private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); public void Execute(IJobExecutionContext context) { try { lock (key) { log.Info("开始……………………………………………………………………"); Execute(); log.Info("结束……………………………………………………………………"); } } catch (Exception ex) { log.Error(ex.ToString()); } } private void Execute() { string erpName = ICSHelper.GetConfigString()["ERPDB"]; string conStr = ICSHelper.GetConnectString(); string Namespace = this.GetType().Namespace; //string Class = this.GetType().Name; DataTable dt = ICSHelper.GetOldERPDB(conStr); foreach (DataRow dr1 in dt.Rows) { string WorkPoint = dr1["WorkPointCode"].ToString(); string Class = this.GetType().Name + WorkPoint; string sql = @"select a.* from IcsMatCheckResult a with(nolock) where 1=1 and a.WorkPoint='KC47' and a.CheckNo='CR202410290034' --and a.IsCheckComplete='是' --and a.AsnCode='DNA08S000072400088' --and a.InvCode='8S11332' --and a.InvBatcgNo='' order by a.Mtime desc "; DataTable dtInInfo = ICSHelper.ExecuteTable(conStr, sql); if (dtInInfo == null || dtInInfo.Rows.Count == 0) { return; } string MailOpen = ICSHelper.GetConfigString("MailOpen"); if (MailOpen != "true") { return; } string SendHost = ICSHelper.GetConfigString("SendHost"); string StrSendPort = ICSHelper.GetConfigString("SendPort"); int SendPort = 25; if (!string.IsNullOrEmpty(StrSendPort)) SendPort = Convert.ToInt32(ICSHelper.GetConfigString("SendPort")); string SendDisplayName = ICSHelper.GetConfigString("SendDisplayName"); string SendAddress = ICSHelper.GetConfigString("SendAddress"); string SendPassword = ICSHelper.GetConfigString("SendPassword"); string sqls = @" select * from V_QuerySysEnumItem a where a.F_EnCode = 'SQESendMail'"; DataTable dts = ICSHelper.ExecuteTable(conStr, sqls); string Email = string.Empty; foreach (DataRow drs in dts.Rows) { Email += drs["Ext1"].ToString() + ","; } foreach (DataRow dr in dtInInfo.Rows) { string TOAddress = Email.TrimEnd(','); string CCAddress = ""; string Subject = "SQE复判提醒"; bool isBodyHtml = true; //string VenName = dr["VENDORNAME"].ToString(); //string STNO = dr["STNO"].ToString(); string NowDate = DateTime.Now.GetDateTimeFormats('D')[0].ToString(); string body = "SQE复判" + ":"; body += "\r\n"; body += " 您好!有一个来料复判的检验单,单号为:" + dr["CheckNo"].ToString() + " 的检验单已经超过48小时没有复判,请及时处理 !"; body += "\r\n"; body += " 苏州咖博士咖啡系统科技有限公司"; body += "\r\n"; body += " " + NowDate; //string StrConn = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString; SendEmail(conStr, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body); } } } public void SendEmail(string ConnectionString, string SendHost, int SendPort, string SendDisplayName, string SendAddress, string SendPassword, string TOAddress, string CCAddress, string Subject, bool IsBodyHtml, string Body) { try { SmtpClient smtpClient = new SmtpClient { //EnableSsl = false, UseDefaultCredentials = false, Host = SendHost, Port = SendPort, Credentials = new NetworkCredential(SendAddress, SendPassword) }; MailMessage mailMessage = new MailMessage { Subject = Subject, SubjectEncoding = Encoding.GetEncoding("utf-8"), BodyEncoding = Encoding.GetEncoding("utf-8"), From = new MailAddress(SendAddress, SendDisplayName), IsBodyHtml = IsBodyHtml, Body = Body }; string[] array = TOAddress.Split(new char[] { ',' }); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string text = array2[i]; if (!string.IsNullOrEmpty(text)) { mailMessage.To.Add(text); } } string[] array3 = CCAddress.Split(new char[] { ',' }); array2 = array3; for (int i = 0; i < array2.Length; i++) { string text2 = array2[i]; if (!string.IsNullOrEmpty(text2)) { mailMessage.CC.Add(text2); } } ServicePointManager.ServerCertificateValidationCallback = ((object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) => true); smtpClient.Send(mailMessage); //InsertData(ConnectionString, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, IsBodyHtml, Body, "1", null); } catch (Exception ex) { //InsertData(ConnectionString, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, IsBodyHtml, Body, "2", ex.Message); throw ex; } } } }