public void sendMail() { ICommonHandler handler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; doEmailProcess dtEmail = new doEmailProcess(); dtEmail.MailFrom = "*****@*****.**"; dtEmail.MailFromAlias = "test"; dtEmail.MailTo = "*****@*****.**"; dtEmail.Message = "This is test send email process from SECOM" + Environment.NewLine + Environment.NewLine + "これは、テストがセコムからのメール送信処理です。" + Environment.NewLine + Environment.NewLine + "Time stamp :" + DateTime.Now.ToString() ; dtEmail.Subject = "SECOM-AJIS Test send mail"; handler.SendMail(dtEmail); }
///<summary> ///Purpose: /// Mandatory check /// ///Parameters: /// doMailProcess: /// MailTo: "" /// Subject: null /// Message: "" /// ///Expected: /// MSG0007: "This field was required: Subject." ///</summary> public string Case2() { ICommonHandler target = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; doEmailProcess param = new doEmailProcess(); param.MailTo = ""; param.Subject = null; param.Message = ""; string expected = "MSG0007"; string actual; try { actual = target.SendMail(param).ToString(); } catch (ApplicationErrorException ex) { actual = ex.ErrorResult.Message.Code; } catch (Exception ex) { actual = ex.StackTrace; } return(string.Format(RESULT_FORMAT, 2, expected, actual, CompareResult_String(expected, actual))); }
public bool SendEmailChangePlanBeforeStart(doChangePlanBeforeStartEmail templateObj) { try { if (templateObj == null) { throw new ArgumentNullException("templateObj"); } ICommonHandler common = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; var config = common.GetSystemConfig(ConfigName.C_CONFIG_CHANGEPLAN_BEFORE_START_EMAIL).FirstOrDefault(); if (config == null) { throw new ApplicationException("Missing tbs_configuration : " + ConfigName.C_CONFIG_CHANGEPLAN_BEFORE_START_EMAIL); } EmailTemplateUtil mailUtil = new EmailTemplateUtil(EmailTemplateName.C_EMAIL_TEMPLATE_NAME_CHANGEPLAN_BEFORE_START); var mailTemplate = mailUtil.LoadTemplate(templateObj); doEmailProcess mailMsg = new doEmailProcess(); mailMsg.MailFrom = CommonUtil.dsTransData.dtUserData.EmailAddress; mailMsg.MailFromAlias = null; mailMsg.MailTo = config.ConfigValue; mailMsg.Subject = mailTemplate.TemplateSubject; mailMsg.Message = mailTemplate.TemplateContent; mailMsg.IsBodyHtml = true; ICommonHandler comHandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; comHandler.SendMail(mailMsg); return(true); } catch (Exception) { throw; } }
///<summary> ///Purpose: /// Mandatory check /// ///Parameters: /// doMailProcess: /// MailTo: [email protected] /// MailFrom: [email protected] /// MailFromAlias: SECOM-AJIS /// Subject: test /// Message: last case /// ///Expected: /// From: [email protected] /// From (Display name): SECOM-AJIS /// Header (Subject): test /// Body (Content): last case /// ///</summary> public string Case4() { ICommonHandler target = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; doEmailProcess param = new doEmailProcess(); param.MailTo = "*****@*****.**"; param.MailFrom = "*****@*****.**"; param.MailFromAlias = "SECOM-AJIS"; param.Subject = "test"; param.Message = "last case"; string expected = null; string actual = null; try { target.SendMail(param).ToString(); } catch (ApplicationErrorException ex) { actual = ex.ErrorResult.Message.Code; } catch (Exception ex) { actual = ex.StackTrace; } return(string.Format(RESULT_FORMAT, 4, expected, actual, CompareResult_String(expected, actual))); }
public static void SendMail(object o) { try { SendMailObject obj = o as SendMailObject; if (obj == null) { return; } if (obj.EmailList != null) { ICommonHandler chandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; foreach (doEmailProcess mail in obj.EmailList) { chandler.SendMail(mail); } } } catch { } }
/// <summary> /// To send notify email for change contract fee /// </summary> /// <param name="UserId"></param> /// <param name="BatchDate"></param> /// <returns></returns> public SECOM_AJIS.Common.Util.doBatchProcessResult SendNotifyEmailForChangeFee(string UserId, DateTime BatchDate) { SECOM_AJIS.Common.Util.doBatchProcessResult doResult = new SECOM_AJIS.Common.Util.doBatchProcessResult(); try { ILogHandler handLog = ServiceContainer.GetService <ILogHandler>() as ILogHandler; //1. Get list of unsent email List <tbt_ContractEmail> dtTbt_ContractEmail = this.GetUnsentNotifyEmail(); //2. For each unsent email in dtTbt_ContractEmail int failedItem = 0; int completdeItem = 0; foreach (tbt_ContractEmail email in dtTbt_ContractEmail) { //2.1 Prepare destination email //2.1.1 Get employee data of destination email IEmployeeMasterHandler handMaster = ServiceContainer.GetService <IEmployeeMasterHandler>() as IEmployeeMasterHandler; List <tbm_Employee> dtEmployee = handMaster.GetTbm_Employee(email.ToEmpNo); //2.1.2 If dtEmployee is empty if (dtEmployee.Count <= 0) { handLog.WriteWindowLog(EventType.C_EVENT_TYPE_ERROR, (MessageUtil.GetMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3077, email.ToEmpNo)).Message, EventID.C_EVENT_ID_NOTIFY_EMAIL_ERROR); failedItem += 1; continue; } //2.1.3 Get default email if endDate is not empty String strEmailTo = (dtEmployee[0].EndDate != null) ? this.getEmailsOfDefaultDepartment() : dtEmployee[0].EmailAddress; //2.2 Prepare email object for sending doEmailProcess emailProc = new doEmailProcess(); emailProc.MailTo = strEmailTo; emailProc.MailFrom = email.EmailFrom; emailProc.Subject = email.EmailSubject; emailProc.Message = email.EmailContent; //2.3 Send email //2.3.1 Retry for 3 times while strStatus is still fails int retry = 0; do { try { ICommonHandler commonHand = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; commonHand.SendMail(emailProc); break; } catch (Exception) { retry += 1; } } while (retry < 3); ICommonContractHandler comContractHand = ServiceContainer.GetService <ICommonContractHandler>() as ICommonContractHandler; if (retry == 3) { failedItem += 1; email.FailSendingCounter = (email.FailSendingCounter == null) ? 1 : email.FailSendingCounter + 1; email.UpdateBy = UserId; //Update to database comContractHand.UpdateTbt_ContractEmail(email); //Check the number of fail for reporting error if (email.FailSendingCounter >= 6 && email.FailSendingCounter % 3 == 0) { handLog.WriteWindowLog(EventType.C_EVENT_TYPE_ERROR, (MessageUtil.GetMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3078, strEmailTo)).Message, EventID.C_EVENT_ID_NOTIFY_EMAIL_ERROR); } } else { completdeItem += 1; //Delete sent email comContractHand.DeleteTbt_ContractEmail(email.ContractEmailID, UserId); } } //3. Prepare process result for returning doResult.Result = FlagType.C_FLAG_ON; doResult.Total = dtTbt_ContractEmail.Count; doResult.Complete = completdeItem; doResult.Failed = failedItem; } catch (Exception) { throw; } return(doResult); }
public ActionResult TestSendMail() { ObjectResultData res = new ObjectResultData(); try { ICommonHandler handler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; //doEmailProcess dtEmail = new doEmailProcess(); ////dtEmail.MailFrom = "*****@*****.**"; ////dtEmail.MailFromAlias = "Narupon"; //dtEmail.MailTo = "[email protected] ; [email protected] ; [email protected] ; [email protected] ; [email protected] ; [email protected]"; //dtEmail.Message = "This is test send email process from SECOM" + Environment.NewLine + Environment.NewLine // + "ทดสอบการส่งอีกเมลจาก SECOM" + Environment.NewLine + Environment.NewLine // + "これは、テストがセコムからのメール送信処理です。" + Environment.NewLine + Environment.NewLine // + "Time stamp :" + DateTime.Now.ToString() // ; //dtEmail.Subject = "SECOM-AJIS Test send mail"; //handler.SendMail(dtEmail); string strEmailTemplateName = EmailTemplateName.C_EMAIL_TEMPLATE_NAME_AR_RETURNED; EmailTemplateUtil mailUtil = new EmailTemplateUtil(strEmailTemplateName); doEmailWithURL templateObj = new doEmailWithURL(); templateObj.ViewURL = "-LinkEN-"; templateObj.ViewURLLC = "-LinkLC-"; templateObj.ARRelatedCode = "-ARRelatedCode-"; templateObj.ARRequestNo = "-ARRequestNo-"; templateObj.ARTypeEN = "-ARTypeEN-"; templateObj.ARTypeLC = "-ARTypeLC-"; templateObj.ARTitleEN = "-ARTitleEN-"; templateObj.ARTitleLC = "-ARTitleLC-"; templateObj.ARSubtitle = "-ARSubtitle-"; templateObj.ARPurpose = "-ARPurpose-"; var mailTemplate = mailUtil.LoadTemplate(templateObj); doEmailProcess mailMsg = new doEmailProcess(); mailMsg.MailFrom = "*****@*****.**"; mailMsg.MailFromAlias = "Jutarat"; mailMsg.MailTo = "*****@*****.**"; mailMsg.Subject = mailTemplate.TemplateSubject; mailMsg.Message = mailTemplate.TemplateContent; handler.SendMail(mailMsg); ViewBag.SendEmailResult = "Send e-mail is completed."; } catch (Exception ex) { res.AddErrorMessage(ex); ViewBag.SendEmailResult = "Send e-mail is failed."; } return(View()); }