public void SendMailWithConfigAction(Action <Workflow, WfActivity> configurationAction, IEmailSender emailSender) { using (new WorkflowRunContext { RunTriggersInCurrentThread = true }) { var emailAction = new SendEmailActivity( ); var emailActionAs = emailAction.Cast <WfActivity>( ); var wf = new Workflow { Name = "Wf" }; wf.AddDefaultExitPoint( ); wf.ContainedActivities.Add(emailActionAs); wf.FirstActivity = emailActionAs; configurationAction(wf, emailActionAs); ActivityTestHelper.AddTermination(wf, emailActionAs); wf.Save( ); ToDelete.Add(wf.Id); using (var scope = Factory.Current.BeginLifetimeScope(builder => { builder.RegisterInstance <IEmailSender>(emailSender); })) using (Factory.SetCurrentScope(scope)) { var wfRun = TestBase.RunWorkflow(wf); Assert.That(wfRun.WorkflowRunStatus_Enum, Is.EqualTo(WorkflowRunState_Enumeration.WorkflowRunCompleted)); } } }
public void SendDelegationEmail(VehicleManagement model, EmailTemplate EmailTempalte, List <EmployeeInfo> toUsers, string webUrl) { var link = string.Format(@"{0}/Lists/VehicleManagement/EditForm.aspx?subSection=TransportationManagement&ID={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", webUrl, model.ID); var department = DepartmentListSingleton.GetDepartmentByID(model.CommonDepartment.LookupId, this.SiteUrl); SendEmailActivity sendMailActivity = new SendEmailActivity(); if (toUsers != null) { foreach (var toUser in toUsers) { try { if (!string.IsNullOrEmpty(toUser.Email)) { var content = HTTPUtility.HtmlDecode(EmailTempalte.MailBody); content = content.Replace("{0}", toUser.FullName); content = content.Replace("{1}", model.Requester.LookupValue); content = content.Replace("{2}", model.From.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{3}", model.ToDate.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{4}", department.Name); content = content.Replace("{5}", department.VietnameseName); content = content.Replace("#link", link); sendMailActivity.SendMail(webUrl, EmailTempalte.MailSubject, toUser.Email, true, false, content); } } catch { } } } }
public void SendEmail(BusinessTripManagement businessTripManagement, EmailTemplate emailTemplate, EmployeeInfo approver, EmployeeInfo toUser, string webUrl, bool isApprovalLink) { if (toUser == null || string.IsNullOrEmpty(toUser.Email) || emailTemplate == null || businessTripManagement == null || string.IsNullOrEmpty(webUrl)) { return; } var content = HTTPUtility.HtmlDecode(emailTemplate.MailBody); content = content.Replace("{0}", toUser.FullName); if (emailTemplate.MailKey.ToLower() == "businesstripmanagement_approve" || emailTemplate.MailKey.ToLower() == "businesstripmanagement_reject") { content = content.Replace("{1}", approver.FullName); content = content.Replace("{2}", businessTripManagement.Requester.LookupValue); content = content.Replace("{3}", businessTripManagement.BusinessTripPurpose); string typeOfBusinessTrip = ""; if (businessTripManagement.Domestic) { typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1033); content = content.Replace("{4}", typeOfBusinessTrip); typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1066); content = content.Replace("{5}", typeOfBusinessTrip); } else { typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1033); content = content.Replace("{4}", typeOfBusinessTrip); typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1066); content = content.Replace("{5}", typeOfBusinessTrip); } } else { content = content.Replace("{1}", businessTripManagement.Requester.LookupValue); content = content.Replace("{2}", businessTripManagement.BusinessTripPurpose); string typeOfBusinessTrip = ""; if (businessTripManagement.Domestic) { typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1033); content = content.Replace("{3}", typeOfBusinessTrip); typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1066); content = content.Replace("{4}", typeOfBusinessTrip); } else { typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1033); content = content.Replace("{3}", typeOfBusinessTrip); typeOfBusinessTrip = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1066); content = content.Replace("{4}", typeOfBusinessTrip); } } var link = GetEmailLinkByUserPosition(webUrl, toUser.EmployeePosition.LookupId, businessTripManagement.ID, isApprovalLink); content = content.Replace("#link", link); SendEmailActivity sendMailActivity = new SendEmailActivity(); sendMailActivity.SendMail(webUrl, emailTemplate.MailSubject, toUser.Email, true, false, content); }
public EmailService() { WebUrl = SPContext.Current.Web.Url; _emailTemplateDAL = new EmailTemplateDAL(WebUrl); _employeeDAL = new EmployeeInfoDAL(WebUrl); _changeShiftManagementDAL = new ChangeShiftManagementDAL(WebUrl); _notOvertimeMangementDAL = new NotOvertimeManagementDAL(WebUrl); _shiftTimeDAL = new ShiftTimeDAL(WebUrl); _sendMailActivity = new SendEmailActivity(); }
//customizing the default activity validation public override ValidationErrorCollection ValidateProperties(ValidationManager manager, object obj) { // Create a new collection for storing the validation errors ValidationErrorCollection validationErrors = base.ValidateProperties(manager, obj); SendEmailActivity activity = obj as SendEmailActivity; if (activity != null) { // Validate the Email and SMTP Properties this.ValidateEmailProperties(validationErrors, activity); this.ValidateSMTPProperties(validationErrors, activity); } return(validationErrors); }
private void SendEmail(string webUrl, int changeshiftItemId, string emailKey, string approverFullName) { SendEmailActivity sendMailActity = new SendEmailActivity(); Thread thread = new Thread(delegate() { var _emailTemplateDAL = new EmailTemplateDAL(webUrl); var _employeeDAL = new EmployeeInfoDAL(webUrl); var _shiftTimeDAL = new ShiftTimeDAL(webUrl); var _sendMailActivity = new SendEmailActivity(); var changeShiftManagementItem = _changeShiftManagementDAL.GetByID(changeshiftItemId); var changeshiftRequestMailItem = _emailTemplateDAL.GetByKey(emailKey); if (changeshiftRequestMailItem != null && changeShiftManagementItem != null) { var employee = _employeeDAL.GetByID(changeShiftManagementItem.Requester.LookupId); if (employee != null && !string.IsNullOrEmpty(employee.Email)) { var shiftTimeList = _shiftTimeDAL.GetShiftTimes(); string emailBody = HTTPUtility.HtmlDecode(changeshiftRequestMailItem.MailBody); var fromShiftItem = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.FromShift.LookupId).FirstOrDefault(); var toShiftItem = shiftTimeList.Where(x => x.ID == changeShiftManagementItem.ToShift.LookupId).FirstOrDefault(); //lookup email string link = $"{webUrl}/{StringConstant.WebPageLinks.ChangeShiftMember}"; if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.Administrator) { link = $"{webUrl}/{StringConstant.WebPageLinks.ChangeShiftAdmin}"; } if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.DepartmentHead) { link = $"{webUrl}/{StringConstant.WebPageLinks.ChangeShiftManager}"; } emailBody = string.Format(emailBody, employee.FullName, changeShiftManagementItem.Requester.LookupValue, changeShiftManagementItem.FromDate.ToString(StringConstant.DateFormatddMMyyyy2), changeShiftManagementItem.ToDate.ToString(StringConstant.DateFormatddMMyyyy2), changeShiftManagementItem.Reason, fromShiftItem.Code, toShiftItem.Code, changeShiftManagementItem.Comment, approverFullName); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(webUrl, changeshiftRequestMailItem.MailSubject, employee.Email, true, false, emailBody); } } }); thread.IsBackground = true; thread.Start(); }
public void SendEmail(FreightManagement freightManagementItem, EmailTemplate emailTemplate, EmployeeInfo approver, EmployeeInfo toUser, string webUrl, bool isApprovalLink) { if (toUser == null || string.IsNullOrEmpty(toUser.Email) || emailTemplate == null || freightManagementItem == null || string.IsNullOrEmpty(webUrl)) { return; } var content = HTTPUtility.HtmlDecode(emailTemplate.MailBody); var bringerName = string.Empty; var bringerNameInVietnamese = string.Empty; if (freightManagementItem.CompanyVehicle) { bringerName = ResourceHelper.GetLocalizedString("FreightRequest_CompanyVehicle", StringConstant.ResourcesFileWebPages, 1033); bringerNameInVietnamese = ResourceHelper.GetLocalizedString("FreightRequest_CompanyVehicle", StringConstant.ResourcesFileWebPages, 1066); } else { bringerName = bringerNameInVietnamese = freightManagementItem.Bringer.LookupId > 0 ? freightManagementItem.Bringer.LookupValue : freightManagementItem.BringerName; } if (emailTemplate.MailKey.ToLower() == "freightmanagement_approve" || emailTemplate.MailKey.ToLower() == "freightmanagement_reject") { content = content.Replace("{0}", toUser.FullName); content = content.Replace("{1}", approver.FullName); content = content.Replace("{2}", freightManagementItem.Requester.LookupValue); content = content.Replace("{3}", bringerName); content = content.Replace("{4}", freightManagementItem.Receiver); content = content.Replace("{5}", bringerNameInVietnamese); } else { content = content.Replace("{0}", toUser.FullName); content = content.Replace("{1}", freightManagementItem.Requester.LookupValue); content = content.Replace("{2}", bringerName); content = content.Replace("{3}", freightManagementItem.Receiver); content = content.Replace("{4}", bringerNameInVietnamese); } var link = GetEmailLinkByUserPosition(webUrl, toUser.EmployeePosition.LookupId, freightManagementItem.ID, isApprovalLink); content = content.Replace("#link", link); SendEmailActivity sendMailActivity = new SendEmailActivity(); sendMailActivity.SendMail(webUrl, emailTemplate.MailSubject, toUser.Email, true, false, content); }
public void SendDelegationEmail(BusinessTripManagement businessTripManagement, EmailTemplate emailTemplate, List <EmployeeInfo> toUsers, string webUrl) { if (toUsers == null || toUsers.Count == 0 || emailTemplate == null || businessTripManagement == null || string.IsNullOrEmpty(webUrl)) { return; } string typeOfBusinessTripEN = ""; string typeOfBusinessTripVN = ""; if (businessTripManagement.Domestic) { typeOfBusinessTripEN = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1033); typeOfBusinessTripVN = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeInternalTitle", StringConstant.ResourcesFileLists, 1066); } else { typeOfBusinessTripEN = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1033); typeOfBusinessTripVN = ResourceHelper.GetLocalizedString("BusinessTripManagement_BusinessTripTypeExternalTitle", StringConstant.ResourcesFileLists, 1066); } var link = string.Format(@"{0}/SitePages/BusinessTripRequest.aspx?subSection=BusinessTripManagement&itemId={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", webUrl, businessTripManagement.ID); SendEmailActivity sendMailActivity = new SendEmailActivity(); foreach (var toUser in toUsers) { try { if (!string.IsNullOrEmpty(toUser.Email)) { var content = HTTPUtility.HtmlDecode(emailTemplate.MailBody); content = content.Replace("{0}", toUser.FullName); content = content.Replace("{1}", businessTripManagement.Requester.LookupValue); content = content.Replace("{2}", businessTripManagement.BusinessTripPurpose); content = content.Replace("{3}", typeOfBusinessTripEN); content = content.Replace("{4}", typeOfBusinessTripVN); content = content.Replace("#link", link); sendMailActivity.SendMail(webUrl, emailTemplate.MailSubject, toUser.Email, true, false, content); } } catch { } } }
public void SendDelegationEmail(FreightManagement freightManagementItem, EmailTemplate emailTemplate, List <EmployeeInfo> toUsers, string webUrl) { if (toUsers == null || toUsers.Count == 0 || emailTemplate == null || freightManagementItem == null || string.IsNullOrEmpty(webUrl)) { return; } SendEmailActivity sendMailActivity = new SendEmailActivity(); var link = string.Format(@"{0}/SitePages/FreightRequest.aspx?subSection=FreightManagement&itemId={1}&Source=/_layouts/15/RBVH.Stada.Intranet.WebPages/DelegationManagement/DelegationList.aspx&Source=Tab=DelegationsApprovalTab", webUrl, freightManagementItem.ID); foreach (var toUser in toUsers) { try { if (!string.IsNullOrEmpty(toUser.Email)) { var content = HTTPUtility.HtmlDecode(emailTemplate.MailBody); var bringerName = string.Empty; var bringerNameInVietnamese = string.Empty; if (freightManagementItem.CompanyVehicle) { bringerName = ResourceHelper.GetLocalizedString("FreightRequest_CompanyVehicle", StringConstant.ResourcesFileWebPages, 1033); bringerNameInVietnamese = ResourceHelper.GetLocalizedString("FreightRequest_CompanyVehicle", StringConstant.ResourcesFileWebPages, 1066); } else { bringerName = bringerNameInVietnamese = freightManagementItem.Bringer.LookupId > 0 ? freightManagementItem.Bringer.LookupValue : freightManagementItem.BringerName; } content = content.Replace("{0}", toUser.FullName); content = content.Replace("{1}", freightManagementItem.Requester.LookupValue); content = content.Replace("{2}", bringerName); content = content.Replace("{3}", freightManagementItem.Receiver); content = content.Replace("{4}", bringerNameInVietnamese); content = content.Replace("#link", link); sendMailActivity.SendMail(webUrl, emailTemplate.MailSubject, toUser.Email, true, false, content); } } catch { } } }
public void SendEmail(string webUrl, int notOvertimeItemId, string emailKey, string approverName) { Thread thread = new Thread(delegate () { var _emailTemplateDAL = new EmailTemplateDAL(webUrl); var _employeeDAL = new EmployeeInfoDAL(webUrl); var _shiftTimeDAL = new ShiftTimeDAL(webUrl); var _sendMailActivity = new SendEmailActivity(); var notOvertimeRequestMailItem = _emailTemplateDAL.GetByKey(emailKey); var notOvertimeManagementItem = _notOvertimeManagementDAL.GetByID(notOvertimeItemId); if (notOvertimeRequestMailItem != null && notOvertimeManagementItem != null) { var employee = _employeeDAL.GetByID(notOvertimeManagementItem.Requester.LookupId); if (employee != null && !string.IsNullOrEmpty(employee.Email)) { string emailBody = HTTPUtility.HtmlDecode(notOvertimeRequestMailItem.MailBody); //lookup email string link = $"{webUrl}/{StringConstant.WebPageLinks.LeaveOfAbsenceMember}"; if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.Administrator) { link = $"{webUrl}/{StringConstant.WebPageLinks.LeaveOfAbsenceAdmin}"; } if (employee.EmployeePosition.LookupId == (int)StringConstant.EmployeePosition.DepartmentHead) { link = $"{webUrl}/{StringConstant.WebPageLinks.LeaveOfAbsenceManager}"; } emailBody = string.Format(emailBody, employee.FullName, notOvertimeManagementItem.Requester.LookupValue, notOvertimeManagementItem.Date.ToString(StringConstant.DateFormatddMMyyyy2), notOvertimeManagementItem.Reason, notOvertimeManagementItem.Comment, approverName); emailBody = emailBody.Replace("#link", link); _sendMailActivity.SendMail(webUrl, notOvertimeRequestMailItem.MailSubject, employee.Email, true, false, emailBody); } } }); thread.IsBackground = true; thread.Start(); }
public ShiftManagementEventReceiver() { _sendMailActivity = new SendEmailActivity(); }
private void ValidateSMTPProperties(ValidationErrorCollection validationErrors, SendEmailActivity activity) { // Validate the SMTPHost property if (String.IsNullOrEmpty(activity.SmtpHost)) { validationErrors.Add(ValidationError.GetNotSetValidationError(SendEmailActivity.SmtpHostProperty.Name)); } // Validate the Port property if (activity.Port == 0) { validationErrors.Add(ValidationError.GetNotSetValidationError(SendEmailActivity.PortProperty.Name)); } else if (activity.Port < 1) { validationErrors.Add(new ValidationError("Invalid Port Number", InvalidSMTPPort, false, SendEmailActivity.PortProperty.Name)); } }
private void ValidateEmailProperties(ValidationErrorCollection validationErrors, SendEmailActivity activity) { // Validate the To property if (String.IsNullOrEmpty(activity.To)) { validationErrors.Add(ValidationError.GetNotSetValidationError(SendEmailActivity.ToProperty.Name)); } else if (!activity.To.Contains("@")) { validationErrors.Add(new ValidationError("Invalid To e-mail address", InvalidToAddress, false, SendEmailActivity.ToProperty.Name)); } // Validate the From property if (String.IsNullOrEmpty(activity.From)) { validationErrors.Add(ValidationError.GetNotSetValidationError(SendEmailActivity.FromProperty.Name)); } else if (!activity.From.Contains("@")) { validationErrors.Add(new ValidationError("Invalid From e-mail address", InvalidFromAddress, false, SendEmailActivity.FromProperty.Name)); } }
public void SendEmail(VehicleManagement model, EmailTemplate EmailTempalte, EmployeeInfo approver, EmployeeInfo toUser, VehicleTypeOfEmail typeOfEmail, string webUrl) { var sendToEmail = string.Empty; var receiverName = string.Empty; var link = string.Empty; var approveLinkFormat = "{0}/Lists/VehicleManagement/EditForm.aspx?subSection=TransportationManagement&ID={1}&Source={2}"; switch (toUser.EmployeePosition.LookupId) { case (int)StringConstant.EmployeePosition.Administrator: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementAdmin"); break; case (int)StringConstant.EmployeePosition.DepartmentHead: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementManager"); break; case (int)StringConstant.EmployeePosition.BOD: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementBOD"); break; default: link = string.Format(LINK_MAIL, webUrl, "TransportationManagementMember"); break; } if (typeOfEmail == VehicleTypeOfEmail.Request) { link = string.Format(approveLinkFormat, webUrl, model.ID, HttpUtility.UrlEncode(link + "#tab2")); } else { link = string.Format(approveLinkFormat, webUrl, model.ID, HttpUtility.UrlEncode(link)); } sendToEmail = toUser.Email; receiverName = toUser.FullName; var content = HTTPUtility.HtmlDecode(EmailTempalte.MailBody); var department = DepartmentListSingleton.GetDepartmentByID(model.CommonDepartment.LookupId, this.SiteUrl); switch (typeOfEmail) { case VehicleTypeOfEmail.Request: content = content.Replace("{0}", receiverName); content = content.Replace("{1}", model.Requester.LookupValue); content = content.Replace("{2}", model.From.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{3}", model.ToDate.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{4}", department.Name); content = content.Replace("{5}", department.VietnameseName); break; case VehicleTypeOfEmail.Approve: case VehicleTypeOfEmail.Reject: content = content.Replace("{0}", model.Requester.LookupValue); content = content.Replace("{1}", approver.FullName); content = content.Replace("{2}", model.From.ToString("dd/MM/yyy hh:mm")); content = content.Replace("{3}", model.ToDate.ToString("dd/MM/yyy hh:mm")); break; default: break; } content = content.Replace("#link", link); SendEmailActivity sendMailActivity = new SendEmailActivity(); sendMailActivity.SendMail(webUrl, EmailTempalte.MailSubject, sendToEmail, true, false, content); }