public async Task <ResponseAC> AddTemplate(long userId, TemplateDetailAC templateDetailAC, string loginUserName) { ResponseAC responseAC = new ResponseAC(); if (await _dbTeleBilling_V01Context.Emailtemplate.FirstOrDefaultAsync(x => x.EmailTemplateTypeId == templateDetailAC.EmailTemplateTypeId) == null) { Emailtemplate emailTemplate = _mapper.Map <Emailtemplate>(templateDetailAC); emailTemplate.CreatedBy = userId; emailTemplate.CreatedDate = DateTime.Now; emailTemplate.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID(); await _dbTeleBilling_V01Context.AddAsync(emailTemplate); await _dbTeleBilling_V01Context.SaveChangesAsync(); responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success); responseAC.Message = _iStringConstant.TemplateAddedSuccessfully; await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.AddEmailTemplate, loginUserName, userId, "Email template(" + emailTemplate.Subject + ")", (int)EnumList.ActionTemplateTypes.Add, emailTemplate.Id); } else { responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error); responseAC.Message = _iStringConstant.TemplateTypeAlreadyExists; } return(responseAC); }
public static EmailTemplateDto FromModel(Emailtemplate model) { return(new EmailTemplateDto { Id = model.Id, Content = model.Content }); }
public async Task <bool> SendEmail(long EmailTemplateId, Dictionary <string, string> replacements, string toEmail) { try { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true, true); IConfigurationRoot configuration = builder.Build(); Emailtemplate template = await _dbTeleBilling_V01Context.Emailtemplate.FirstOrDefaultAsync(x => x.EmailTemplateTypeId == EmailTemplateId); if (template != null && !string.IsNullOrEmpty(toEmail)) { string body = template.EmailText; replacements.ToList().ForEach(x => { body = body.Replace(x.Key, Convert.ToString(x.Value)); }); // Plug in your email service here to send an email. var msg = new MimeMessage(); msg.From.Add(new MailboxAddress(template.EmailFrom, template.EmailFrom)); msg.To.Add(new MailboxAddress(toEmail)); if (!string.IsNullOrEmpty(template.EmailBcc)) { msg.Bcc.Add(new MailboxAddress(template.EmailBcc)); } msg.Subject = template.Subject; var bodyBuilder = new BodyBuilder(); bodyBuilder.HtmlBody = body; msg.Body = bodyBuilder.ToMessageBody(); using (var smtp = new SmtpClient()) { smtp.Connect(configuration.GetSection("EmailCrednetials").GetSection("Host").Value, Convert.ToInt16(configuration.GetSection("EmailCrednetials").GetSection("Port").Value), SecureSocketOptions.SslOnConnect); smtp.Authenticate(credentials: new NetworkCredential(configuration.GetSection("EmailCrednetials").GetSection("From").Value, configuration.GetSection("EmailCrednetials").GetSection("Password").Value)); smtp.Send(msg, CancellationToken.None); smtp.Disconnect(true, CancellationToken.None); } return(true); } return(false); } catch (Exception ex) { throw ex; } }
public async Task AddedReminderNotificationLog(long emailTemplateTypeId, long?employeeBillId, bool isReminderMail, string emailTo) { Emailtemplate emailTemplate = await _dbTeleBilling_V01Context.Emailtemplate.FirstOrDefaultAsync(x => x.EmailTemplateTypeId == emailTemplateTypeId); if (emailTemplate != null) { Emailreminderlog newEmailReminderLog = new Emailreminderlog(); newEmailReminderLog.CreatedDate = DateTime.Now; newEmailReminderLog.IsReminderMail = isReminderMail; newEmailReminderLog.TemplateId = emailTemplate.Id; newEmailReminderLog.EmployeeBillId = employeeBillId; newEmailReminderLog.EmailTo = emailTo != null ? emailTo : string.Empty; await _dbTeleBilling_V01Context.AddAsync(newEmailReminderLog); await _dbTeleBilling_V01Context.SaveChangesAsync(); } }
private void compose() { DbModel db = new DbModel(); Emailtemplate emailTemplate = db.Emailtemplate.Where(x => x.name == TemplateName && x.lang == currentLang).First(); string bodyTemplate = emailTemplate.template; string subjectTemplate = emailTemplate.subject; foreach (string k in vars.Keys) { bodyTemplate = bodyTemplate.Replace("%" + k + "%", (string)vars[k]); subjectTemplate = subjectTemplate.Replace("%" + k + "%", (string)vars[k]); } this.IsBodyHtml = true; this.BodyEncoding = System.Text.Encoding.UTF8; this.Subject = subjectTemplate; this.Body = bodyTemplate; }
/// <summary> /// /// </summary> /// <param name="employeeBillServicePackage"></param> /// <param name="employeeBillMasters"></param> private void SendEmailNotificationToEmployee(Employeebillservicepackage employeeBillServicePackage, Employeebillmaster employeeBillMaster) { if (!string.IsNullOrEmpty(employeeBillMaster.Employee.EmailId)) { Dictionary <string, string> replacements = new Dictionary <string, string>(); EnumList.Month month = (EnumList.Month)employeeBillMaster.BillMonth; replacements.Add("{BillNumber}", employeeBillMaster.BillNumber); replacements.Add("{BillMonth}", month.ToString()); replacements.Add("{BillYear}", employeeBillMaster.BillYear.ToString()); replacements.Add("{newEmpName}", employeeBillMaster.Employee.FullName); replacements.Add("{Provider}", employeeBillMaster.Provider.Name); string telphoneNumber = !string.IsNullOrEmpty(employeeBillMaster.TelephoneNumber) ? employeeBillMaster.TelephoneNumber.Trim() : string.Empty; replacements.Add("{TelePhoneNumber}", telphoneNumber); string deductionAmount = string.Empty; if (employeeBillServicePackage.DeductionAmount != null) { deductionAmount = Convert.ToString(employeeBillServicePackage.DeductionAmount); } replacements.Add("{DeductionAmount}", deductionAmount); using (var _dbTeleBillingContext = new telebilling_v01Context()) { long emailTemplateTypeId = Convert.ToInt64(EnumList.EmailTemplateType.SendEmailNotificationToEmployeForAmountToBeDeducted); Emailtemplate emailTemplate = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId); if (emailTemplate != null && !string.IsNullOrEmpty(employeeBillMaster.Employee.EmailId)) { string body = emailTemplate.EmailText; replacements.ToList().ForEach(x => { body = body.Replace(x.Key, Convert.ToString(x.Value)); }); if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, employeeBillMaster.Employee.EmailId)) { AddedReminderNotificationLog(emailTemplate.Id, employeeBillMaster.Id, false, employeeBillMaster.Employee.EmailId); } } } } }
public async Task <ResponseAC> UpdateTemplate(long userId, TemplateDetailAC templateDetailAC, string loginUserName) { ResponseAC responseAC = new ResponseAC(); if (await _dbTeleBilling_V01Context.Emailtemplate.FirstOrDefaultAsync(x => x.EmailTemplateTypeId == templateDetailAC.EmailTemplateTypeId && x.Id != templateDetailAC.Id) == null) { Emailtemplate emailTemplate = await _dbTeleBilling_V01Context.Emailtemplate.FirstOrDefaultAsync(x => x.Id == templateDetailAC.Id); #region Transaction Log Entry if (emailTemplate.TransactionId == null) { emailTemplate.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID(); } var jsonSerailzeObj = JsonConvert.SerializeObject(emailTemplate); await _iLogManagement.SaveRequestTraseLog(Convert.ToInt64(emailTemplate.TransactionId), userId, Convert.ToInt64(EnumList.TransactionTraseLog.UpdateRecord), jsonSerailzeObj); #endregion emailTemplate = _mapper.Map(templateDetailAC, emailTemplate); emailTemplate.UpdatedBy = userId; emailTemplate.UpdatedDate = DateTime.Now; _dbTeleBilling_V01Context.Update(emailTemplate); await _dbTeleBilling_V01Context.SaveChangesAsync(); responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success); responseAC.Message = _iStringConstant.TemplateUpdateSuccessfully; await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.EditEmailTemplate, loginUserName, userId, "Email template(" + emailTemplate.Subject + ")", (int)EnumList.ActionTemplateTypes.Edit, emailTemplate.Id); } else { responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Error); responseAC.Message = _iStringConstant.TemplateTypeAlreadyExists; } return(responseAC); }
void timerReminder_Elapsed(object sender, ElapsedEventArgs e) { using (var _dbTeleBillingContext = new telebilling_v01Context()) { int waitingForIdentificationStatus = Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForIdentification); int waitingForLineManagerApprovalStatus = Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForLineManagerApproval); List <Employeebillmaster> employeeBillMasters = _dbTeleBillingContext.Employeebillmaster.Where(x => !x.IsDelete && (x.EmployeeBillStatus == waitingForIdentificationStatus || x.EmployeeBillStatus == waitingForLineManagerApprovalStatus)).Include(x => x.Provider).Include(x => x.Employee).Include(x => x.Linemanager).Include(x => x.BillDelegatedEmp).ToList(); Configuration configuration = _dbTeleBillingContext.Configuration.First(); DateTime todaydate = DateTime.Now.Date; //mail sending only one time for bill identification if (configuration.NBillAllocationToEmployee) { List <Employeebillmaster> employeeBillMastersForNotiIdentification = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForIdentificationStatus && x.CreatedDate.Date == todaydate).ToList(); if (employeeBillMastersForNotiIdentification.Any()) { int emailTemplateTypeId = Convert.ToInt16(EnumList.EmailTemplateType.EmployeeCallIdentificationNotification); Emailtemplate emailTemplate = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId); if (emailTemplate != null) { foreach (var item in employeeBillMastersForNotiIdentification) { Emailreminderlog emailReminderLog = _dbTeleBillingContext.Emailreminderlog.FirstOrDefault(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && !x.IsReminderMail); if (emailReminderLog == null && !string.IsNullOrEmpty(item.Employee.EmailId)) { Dictionary <string, string> replacements = new Dictionary <string, string>(); EnumList.Month month = (EnumList.Month)item.BillMonth; replacements.Add("{newEmpName}", item.Employee.FullName); replacements.Add("{BillNumber}", item.BillNumber); replacements.Add("{BillMonth}", month.ToString()); replacements.Add("{Provider}", item.Provider.Name); replacements.Add("{BillYear}", item.BillYear.ToString()); replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim()); string body = emailTemplate.EmailText; replacements.ToList().ForEach(x => { body = body.Replace(x.Key, Convert.ToString(x.Value)); }); if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.Employee.EmailId)) { AddedReminderNotificationLog(emailTemplate.Id, item.Id, false, item.Employee.EmailId); } } } } } } //mail sending only one time for bill delegated identification if (configuration.NBillDelegatesForIdentification) { List <Employeebillmaster> employeeBillMastersForDelgatedIdentification = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForIdentificationStatus && x.BillDelegatedEmpId != null).ToList(); if (employeeBillMastersForDelgatedIdentification.Any()) { int emailTemplateForDelegatedTypeId = Convert.ToInt16(EnumList.EmailTemplateType.BillDelegatesForIdentification); Emailtemplate emailTemplate = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateForDelegatedTypeId); if (emailTemplate != null) { foreach (var item in employeeBillMastersForDelgatedIdentification) { Emailreminderlog emailReminderLog = _dbTeleBillingContext.Emailreminderlog.FirstOrDefault(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && !x.IsReminderMail); if (emailReminderLog == null && !string.IsNullOrEmpty(item.BillDelegatedEmp.EmailId)) { Dictionary <string, string> replacements = new Dictionary <string, string>(); EnumList.Month month = (EnumList.Month)item.BillMonth; replacements.Add("{newEmpName}", item.BillDelegatedEmp.FullName); replacements.Add("{BillNumber}", item.BillNumber); replacements.Add("{BillMonth}", month.ToString()); replacements.Add("{Provider}", item.Provider.Name); replacements.Add("{BillYear}", item.BillYear.ToString()); string body = emailTemplate.EmailText; replacements.ToList().ForEach(x => { body = body.Replace(x.Key, Convert.ToString(x.Value)); }); if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.BillDelegatedEmp.EmailId)) { AddedReminderNotificationLog(emailTemplate.Id, item.Id, false, item.BillDelegatedEmp.EmailId); } } } } } } //mail sending only one time for bill identification request approval to line manager if (configuration.NNewBillReceiveForApproval) { List <Employeebillmaster> employeeBillMastersForbillApproval = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForLineManagerApprovalStatus && x.CreatedDate.Date == todaydate).ToList(); if (employeeBillMastersForbillApproval.Any()) { int emailTemplateTypeId = Convert.ToInt16(EnumList.EmailTemplateType.LineManagerApprovalNotification); Emailtemplate emailTemplate = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId); if (emailTemplate != null) { foreach (var item in employeeBillMastersForbillApproval) { Emailreminderlog emailReminderLog = _dbTeleBillingContext.Emailreminderlog.FirstOrDefault(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && !x.IsReminderMail); if (emailReminderLog == null && !string.IsNullOrEmpty(item.Linemanager.EmailId)) { Dictionary <string, string> replacements = new Dictionary <string, string>(); replacements.Add("{newEmpName}", item.Employee.FullName); EnumList.Month month = (EnumList.Month)item.BillMonth; replacements.Add("{BillNumber}", item.BillNumber); replacements.Add("{BillMonth}", month.ToString()); replacements.Add("{BillYear}", item.BillYear.ToString()); replacements.Add("{Provider}", item.Provider.Name); replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim()); string body = emailTemplate.EmailText; replacements.ToList().ForEach(x => { body = body.Replace(x.Key, Convert.ToString(x.Value)); }); if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.Linemanager.EmailId)) { AddedReminderNotificationLog(emailTemplate.Id, item.Id, false, item.Linemanager.EmailId); } } } } } } //mail sending only one time for delegates bill identification request approval to line manager if (configuration.NDelegatesBillForApproval) { List <Employeebillmaster> employeeBillMastersForDelegatesBillApproval = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForLineManagerApprovalStatus && x.CreatedDate.Date == todaydate && x.BillDelegatedEmpId != null).ToList(); if (employeeBillMastersForDelegatesBillApproval.Any()) { int emailTemplateTypeId = Convert.ToInt16(EnumList.EmailTemplateType.DelegateBillApproval); Emailtemplate emailTemplate = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId); if (emailTemplate != null) { foreach (var item in employeeBillMastersForDelegatesBillApproval) { Emailreminderlog emailReminderLog = _dbTeleBillingContext.Emailreminderlog.FirstOrDefault(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && !x.IsReminderMail); if (emailReminderLog == null && !string.IsNullOrEmpty(item.BillDelegatedEmp.EmailId)) { Dictionary <string, string> replacements = new Dictionary <string, string>(); replacements.Add("{newEmpName}", item.Employee.FullName); EnumList.Month month = (EnumList.Month)item.BillMonth; replacements.Add("{BillNumber}", item.BillNumber); replacements.Add("{BillMonth}", month.ToString()); replacements.Add("{BillYear}", item.BillYear.ToString()); replacements.Add("{Provider}", item.Provider.Name); replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim()); string body = emailTemplate.EmailText; replacements.ToList().ForEach(x => { body = body.Replace(x.Key, Convert.ToString(x.Value)); }); if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.BillDelegatedEmp.EmailId)) { AddedReminderNotificationLog(emailTemplate.Id, item.Id, false, item.BillDelegatedEmp.EmailId); } } } } } } //mail sending reminder in perticular interval for bill identification and also delegated employee if (configuration.REmployeeCallIdentificationIsActive) //Included delgated employee { List <Employeebillmaster> employeeBillMastersForREmpCllIdetification = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForIdentificationStatus).ToList(); if (employeeBillMastersForREmpCllIdetification.Any()) { int emailTemplateTypeId = Convert.ToInt16(EnumList.EmailTemplateType.EmployeeCallIdentificationRemider); int emailTemplateTypeForDelegateUserId = Convert.ToInt16(EnumList.EmailTemplateType.BillDelegatesForIdentification); foreach (var item in employeeBillMastersForREmpCllIdetification) { DateTime reminderDate = new DateTime(); Emailreminderlog emailReminderLog = new Emailreminderlog(); //check bill delgated or not if (item.BillDelegatedEmpId != null) { Emailtemplate emailTemplateForDelegateUser = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeForDelegateUserId); if (emailTemplateForDelegateUser != null && !string.IsNullOrEmpty(item.BillDelegatedEmp.EmailId)) { emailReminderLog = _dbTeleBillingContext.Emailreminderlog.Where(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplateForDelegateUser.Id && x.IsReminderMail).OrderByDescending(x => x.CreatedDateInt).FirstOrDefault(); int intervalDay = configuration.REmployeeCallIdentificationInterval != null?Convert.ToInt32(configuration.REmployeeCallIdentificationInterval) : 0; if (emailReminderLog != null) { reminderDate = emailReminderLog.CreatedDate.AddDays(intervalDay); } else { reminderDate = item.CreatedDate.AddDays(intervalDay); } if (reminderDate.Date == DateTime.Now.Date) { Dictionary <string, string> replacements = new Dictionary <string, string>(); replacements.Add("{newEmpName}", item.Employee.FullName); EnumList.Month month = (EnumList.Month)item.BillMonth; replacements.Add("{BillNumber}", item.BillNumber); replacements.Add("{Provider}", item.Provider.Name); replacements.Add("{BillMonth}", month.ToString()); replacements.Add("{BillYear}", item.BillYear.ToString()); replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim()); string body = emailTemplateForDelegateUser.EmailText; replacements.ToList().ForEach(x => { body = body.Replace(x.Key, Convert.ToString(x.Value)); }); if (SendEmail(emailTemplateForDelegateUser.EmailFrom, emailTemplateForDelegateUser.EmailBcc, emailTemplateForDelegateUser.Subject, body, item.BillDelegatedEmp.EmailId)) { AddedReminderNotificationLog(emailTemplateForDelegateUser.Id, item.Id, true, item.BillDelegatedEmp.EmailId); } } } } else { Emailtemplate emailTemplate = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId); if (emailTemplate != null && !string.IsNullOrEmpty(item.Employee.EmailId)) { emailReminderLog = _dbTeleBillingContext.Emailreminderlog.Where(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && x.IsReminderMail).OrderByDescending(x => x.CreatedDateInt).FirstOrDefault(); int intervalDay = configuration.REmployeeCallIdentificationInterval != null?Convert.ToInt32(configuration.REmployeeCallIdentificationInterval) : 0; if (emailReminderLog != null) { reminderDate = emailReminderLog.CreatedDate.AddDays(intervalDay); } else { reminderDate = item.CreatedDate.AddDays(intervalDay); } if (reminderDate.Date == DateTime.Now.Date) { Dictionary <string, string> replacements = new Dictionary <string, string>(); replacements.Add("{newEmpName}", item.Employee.FullName); EnumList.Month month = (EnumList.Month)item.BillMonth; replacements.Add("{BillNumber}", item.BillNumber); replacements.Add("{BillMonth}", month.ToString()); replacements.Add("{BillYear}", item.BillYear.ToString()); replacements.Add("{Provider}", item.Provider.Name); replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim()); string body = emailTemplate.EmailText; replacements.ToList().ForEach(x => { body = body.Replace(x.Key, Convert.ToString(x.Value)); }); if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.Employee.EmailId)) { AddedReminderNotificationLog(emailTemplate.Id, item.Id, true, item.Employee.EmailId); } } } } } } } //mail sending reminder perticular interval for bill identification request approval to line manager if (configuration.RLinemanagerApprovalIsActive) { List <Employeebillmaster> employeeBillMastersForRLineManager = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForLineManagerApprovalStatus).ToList(); if (employeeBillMastersForRLineManager.Any()) { foreach (var item in employeeBillMastersForRLineManager) { DateTime reminderDate = new DateTime(); Emailreminderlog emailReminderLog = new Emailreminderlog(); //check bill delgated or not if (item.BillDelegatedEmpId != null) { int emailTemplateDelegateTypeId = Convert.ToInt16(EnumList.EmailTemplateType.DelegateBillApproval); Emailtemplate emailTemplateForDelegateUser = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateDelegateTypeId); if (emailTemplateForDelegateUser != null && !string.IsNullOrEmpty(item.BillDelegatedEmp.EmailId)) { emailReminderLog = _dbTeleBillingContext.Emailreminderlog.Where(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplateForDelegateUser.Id && x.IsReminderMail).OrderByDescending(x => x.CreatedDateInt).FirstOrDefault(); int intervalDay = configuration.RLinemanagerApprovalInterval != null?Convert.ToInt32(configuration.RLinemanagerApprovalInterval) : 0; if (emailReminderLog != null) { reminderDate = emailReminderLog.CreatedDate.AddDays(intervalDay); } else { reminderDate = item.CreatedDate.AddDays(intervalDay); } if (reminderDate.Date == DateTime.Now.Date) { Dictionary <string, string> replacements = new Dictionary <string, string>(); replacements.Add("{newEmpName}", item.Employee.FullName); EnumList.Month month = (EnumList.Month)item.BillMonth; replacements.Add("{BillNumber}", item.BillNumber); replacements.Add("{BillMonth}", month.ToString()); replacements.Add("{BillYear}", item.BillYear.ToString()); replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim()); string body = emailTemplateForDelegateUser.EmailText; replacements.ToList().ForEach(x => { body = body.Replace(x.Key, Convert.ToString(x.Value)); }); if (SendEmail(emailTemplateForDelegateUser.EmailFrom, emailTemplateForDelegateUser.EmailBcc, emailTemplateForDelegateUser.Subject, body, item.BillDelegatedEmp.EmailId)) { AddedReminderNotificationLog(emailTemplateForDelegateUser.Id, item.Id, true, item.BillDelegatedEmp.EmailId); } } } } else { int emailTemplateTypeId = Convert.ToInt16(EnumList.EmailTemplateType.LineManagerApprovalRemider); Emailtemplate emailTemplate = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId); if (emailTemplate != null && !string.IsNullOrEmpty(item.Linemanager.EmailId)) { emailReminderLog = _dbTeleBillingContext.Emailreminderlog.Where(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && x.IsReminderMail).OrderByDescending(x => x.CreatedDateInt).FirstOrDefault(); int intervalDay = configuration.RLinemanagerApprovalInterval != null?Convert.ToInt32(configuration.RLinemanagerApprovalInterval) : 0; if (emailReminderLog != null) { reminderDate = emailReminderLog.CreatedDate.AddDays(intervalDay); } else { reminderDate = item.CreatedDate.AddDays(intervalDay); } if (reminderDate.Date == DateTime.Now.Date) { Dictionary <string, string> replacements = new Dictionary <string, string>(); replacements.Add("{newEmpName}", item.Employee.FullName); EnumList.Month month = (EnumList.Month)item.BillMonth; replacements.Add("{BillNumber}", item.BillNumber); replacements.Add("{BillMonth}", month.ToString()); replacements.Add("{BillYear}", item.BillYear.ToString()); replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim()); string body = emailTemplate.EmailText; replacements.ToList().ForEach(x => { body = body.Replace(x.Key, Convert.ToString(x.Value)); }); if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.Linemanager.EmailId)) { AddedReminderNotificationLog(emailTemplate.Id, item.Id, true, item.Linemanager.EmailId); } } } } } } } } }
public async Task <TemplateDetailAC> GetTemplateById(long id) { Emailtemplate emailTemplate = await _dbTeleBilling_V01Context.Emailtemplate.FirstOrDefaultAsync(x => x.Id == id); return(_mapper.Map <TemplateDetailAC>(emailTemplate)); }
public void enviarCorreo(string correoDestino, string userToken, string mensaje, string url, string estado) { // inicializar variable var var Emailtemplate = (dynamic)null; if (estado.Equals(Constantes.ESTADO_EN_ESPERA)) { Emailtemplate = new System.IO.StreamReader (AppDomain.CurrentDomain.BaseDirectory.Insert (AppDomain.CurrentDomain.BaseDirectory.Length, "Recursos\\SendMail\\ActivarCuenta.html")); } else if (estado.Equals(Constantes.ESTADO_CAMBIO_PASS)) { Emailtemplate = new System.IO.StreamReader (AppDomain.CurrentDomain.BaseDirectory.Insert (AppDomain.CurrentDomain.BaseDirectory.Length, "Recursos\\SendMail\\CambiarPassword.html")); } var strBody = string.Format(Emailtemplate.ReadToEnd(), userToken); Emailtemplate.Close(); Emailtemplate.Dispose(); Emailtemplate = null; string hostPuerto = HttpContext.Current.Request.Url.Authority; strBody = strBody.Replace("token", "http://" + hostPuerto + url + userToken); //Configuración del Mensaje MailMessage mail = new MailMessage(); //Especificamos el correo desde el que se enviará el Email y el nombre de la persona que lo envía mail.From = new MailAddress("*****@*****.**", "TUdeC"); //Aquí ponemos el asunto del correo mail.Subject = mensaje; //Aquí ponemos el mensaje que incluirá el correo mail.Body = strBody; //Especificamos a quien enviaremos el Email, no es necesario que sea Gmail, puede ser cualquier otro proveedor mail.To.Add(correoDestino); //Si queremos enviar archivos adjuntos tenemos que especificar la ruta en donde se encuentran //mail.Attachments.Add(new Attachment(@"C:\Documentos\carta.docx")); mail.IsBodyHtml = true; mail.Priority = MailPriority.Normal; String HOST = "smtp.gmail.com"; // The port you will connect to on the Amazon SES SMTP endpoint. We // are choosing port 587 because we will use STARTTLS to encrypt // the connection. int PORT = 587; using (var client = new SmtpClient(HOST, PORT)) { client.EnableSsl = true; client.UseDefaultCredentials = false; // Pass SMTP credentials client.Credentials = new System.Net.NetworkCredential(Constantes.CORREO, Constantes.PASSWORD); // Enable SSL encryption // Try to send the message. Show status in console. try { client.Send(mail); mail.Dispose(); } catch (Exception ex) { throw ex; } } }
public async Task <ResponseAC> AddMemo(MemoAC memoAC, long userId, string loginUserName) { ResponseAC responseAC = new ResponseAC(); Memo memo = _mapper.Map <Memo>(memoAC); memo.Id = 0; memo.CreatedBy = userId; memo.CreatedDate = DateTime.Now; memo.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID(); memo.RefrenceNo = memoAC.ProviderName + "/INV/" + memoAC.Month + "/" + memo.Year; _dbTeleBilling_V01Context.Add(memo); await _dbTeleBilling_V01Context.SaveChangesAsync(); List <Memobills> billMemos = new List <Memobills>(); List <Billmaster> billMasters = new List <Billmaster>(); foreach (long item in memoAC.BillIds) { Memobills memoBill = new Memobills(); memoBill.BillId = item; memoBill.MemoId = memo.Id; memoBill.TransactionId = memo.TransactionId; memoBill.CreatedBy = userId; memoBill.CreatedDate = DateTime.Now; billMemos.Add(memoBill); Billmaster billMaster = await _dbTeleBilling_V01Context.Billmaster.FirstOrDefaultAsync(x => x.Id == item); billMaster.UpdatedBy = userId; billMaster.BillStatusId = Convert.ToInt16(EnumList.BillStatus.MemoCreated); billMaster.UpdatedDate = DateTime.Now; billMasters.Add(billMaster); } if (billMemos.Any()) { await _dbTeleBilling_V01Context.AddRangeAsync(billMemos); await _dbTeleBilling_V01Context.SaveChangesAsync(); } if (billMasters.Any()) { _dbTeleBilling_V01Context.UpdateRange(billMasters); await _dbTeleBilling_V01Context.SaveChangesAsync(); memo = await _dbTeleBilling_V01Context.Memo.Where(x => x.Id == memo.Id && !x.IsDelete).Include(x => x.Provider).FirstOrDefaultAsync(); #region Send Mail For Create Memo TeleBillingUtility.Models.Configuration configuration = await _dbTeleBilling_V01Context.Configuration.FirstOrDefaultAsync(); List <MstEmployee> mstEmployees = await _dbTeleBilling_V01Context.MstEmployee.Where(x => !x.IsDelete && x.IsActive && x.IsPresidentOffice).ToListAsync(); if (configuration != null && configuration.NSendMemo) { foreach (var item in billMasters) { if (mstEmployees.Any()) { foreach (var employee in mstEmployees) { if (!string.IsNullOrEmpty(employee.EmailId)) { Emailtemplate emailTemplate = new Emailtemplate(); Dictionary <string, string> replacements = new Dictionary <string, string>(); EnumList.Month month = (EnumList.Month)item.BillMonth; replacements.Add("{BillMonth}", month.ToString()); replacements.Add("{BillYear}", item.BillYear.ToString()); replacements.Add("{RefrenceNo}", memo.RefrenceNo); replacements.Add("{newEmpName}", employee.FullName); replacements.Add("{MemoSubject}", memo.Subject); replacements.Add("{BillNumber}", item.BillNumber); replacements.Add("{BillAmount}", memo.TotalAmount.ToString()); replacements.Add("{Provider}", memo.Provider.Name); if (await _iEmailSender.SendEmail(Convert.ToInt64(EnumList.EmailTemplateType.SendMemo), replacements, employee.EmailId)) { await _iEmailSender.AddedReminderNotificationLog(Convert.ToInt64(EnumList.EmailTemplateType.SendMemo), null, false, employee.EmailId); } } } } } } #endregion #region Notification For Memo List <Notificationlog> notificationlogs = new List <Notificationlog>(); if (mstEmployees.Any()) { foreach (var item in mstEmployees) { notificationlogs.Add(_iLogManagement.GenerateNotificationObject(item.UserId, userId, Convert.ToInt16(EnumList.NotificationType.SendMemo), memo.Id)); } await _iLogManagement.SaveNotificationList(notificationlogs); } #endregion } await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.AddMemo, loginUserName, userId, "Memo(" + memo.RefrenceNo + ")", (int)EnumList.ActionTemplateTypes.Add, memo.Id); responseAC.Message = _iStringConstant.MemoAddedsuccessfully; responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success); return(responseAC); }