public static bool SendMail(List <string> to, List <string> cc, string subject, string body) { string SendMail = "SendMail"; sysErrorMessageDBSet syserrdb = new sysErrorMessageDBSet(); MailMessage message = new MailMessage(); message.From = new MailAddress(Constant.DefaultMailFrom); try { foreach (var item in to) { if (item != null) { if (item.Trim().Length > 0) { message.To.Add(new MailAddress(item)); } } } if (cc != null) { foreach (var item in cc) { if (item != null) { if (item.Trim().Length > 0) { message.CC.Add(new MailAddress(item)); } } } } char[] delimiterChars = { ';' }; string[] bccArray = Constant.DefaultMailBcc.Split(delimiterChars); foreach (string bcc in bccArray) { message.Bcc.Add(new MailAddress(bcc)); } } catch (Exception ex) { message.To.Add(new MailAddress(Constant.DefaultMailBcc)); body += ex.Message; syserrdb.InitErrorData(Src: SendMail, content: body, editor: "IEC891652"); } try { message.IsBodyHtml = true; message.Subject = subject; message.BodyEncoding = Encoding.UTF8; message.Body = body; SmtpClient client = new SmtpClient(Constant.DefaultMailServer); client.Send(message); } catch (Exception ex) { string msg = ex.Message; syserrdb.InitErrorData(Src: SendMail, content: msg, editor: "IEC891652"); } return(true); }
public f_cerl CheckAndPushTask(FormCollection fc, f_cerl f_cerl) { string fnCheckAndPushTask = "RouteWork_CheckAndPushTask"; string UserId = f_cerl.editor; string strAction = f_cerl.Action; string ListAssignTo = ""; int errorline = 233; try { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); StringBuilder vchSet = new StringBuilder(); errorline = 238; FlowPath fp = GetFlowPath(f_cerl.fID, f_cerl.FlowCode, f_cerl.State, f_cerl.Action); // 取得下一關的State errorline = 240; if (fp == null) { return(f_cerl); } if (f_cerl.State >= 1000) { strAction = ""; return(f_cerl); } errorline = 249; if (fp != null) { if (f_cerl.LocalSupervisor == null) { f_cerl.LocalSupervisor = db.vUsers.Where(u => u.RoleId == 20).Select(v => v.BadgeCode).FirstOrDefault();//"IEC970209"; } errorline = 254; if (f_cerl.Manager == null) { f_cerl.Manager = f_cerl.Applicant; } errorline = 257; vchSet.Append(Method.BuildXML(fp.outState.ToString(), "outState")); vchSet.Append(Method.BuildXML(f_cerl.TestItem.ToString(), "TestItem")); vchSet.Append(Method.BuildXML(f_cerl.Supervisor, "Supervisor")); vchSet.Append(Method.BuildXML(f_cerl.LocalSupervisor, "LocalSupervisor")); vchSet.Append(Method.BuildXML(f_cerl.LabMember, "LabMember")); vchSet.Append(Method.BuildXML(f_cerl.Applicant, "Applicant")); vchSet.Append(Method.BuildXML(f_cerl.Manager, "Manager")); vchSet.Append(Method.BuildXML(f_cerl.Action, "")); errorline = 266; GetListAssignTo(fp.outState, vchSet.ToString(), out ListAssignTo); //取得下一關的收件人 f_cerl.ListAssignTo = ListAssignTo; errorline = 269; if (ListAssignTo != "") { errorline = 272; response = PostFormDataToRoute(fc, f_cerl); //Push Task, Send Task mail by AssignTo f_cerl.State = int.Parse(fp.outState.ToString()); db.Entry(f_cerl).State = EntityState.Modified; db.SaveChanges(); errorline = 278; SendMail(fp, f_cerl.fID); errorline = 280; } errorline = 282; } f_cerl.Comment = ""; } catch (Exception ex) { string msg = ex.Message; string newLine = "\r\n"; StringBuilder sb = new StringBuilder(); sb.Append("Issue at line 291: occur error after line " + errorline.ToString() + msg); sb.Append(newLine); sb.Append(f_cerl.ID + " " + f_cerl.State); syserrdb.InitErrorData(Src: fnCheckAndPushTask, content: sb.ToString(), editor: UserId); } return(f_cerl); }