private StringBuilder GetTitleAndSubTitle(int?tenantId, string title, string subTitle) { var emailTemplate = new StringBuilder(_emailTemplateProvider.GetDefaultTemplate(tenantId)); emailTemplate.Replace("{EMAIL_TITLE}", title); emailTemplate.Replace("{EMAIL_SUB_TITLE}", subTitle); return(emailTemplate); }
/// <summary> /// Send email activation link to user's email address. /// </summary> /// <param name="user">User</param> /// <param name="plainPassword"> /// Can be set to user's plain password to include it in the email. /// </param> public async Task SendEmailActivationLinkAsync(User user, string plainPassword = null) { if (user.EmailConfirmationCode.IsNullOrEmpty()) { throw new ApplicationException("EmailConfirmationCode should be set in order to send email activation link."); } var tenancyName = user.TenantId.HasValue ? _tenantRepository.Get(user.TenantId.Value).TenancyName : null; var link = _webUrlService.GetSiteRootAddress(tenancyName) + "Account/EmailConfirmation" + "?userId=" + Uri.EscapeDataString(SimpleStringCipher.Encrypt(user.Id.ToString())) + "&confirmationCode=" + Uri.EscapeDataString(user.EmailConfirmationCode); var emailTemplate = new StringBuilder(_emailTemplateProvider.GetDefaultTemplate()); emailTemplate.Replace("{EMAIL_TITLE}", L("EmailActivation_Title")); emailTemplate.Replace("{EMAIL_SUB_TITLE}", L("EmailActivation_SubTitle")); var mailMessage = new StringBuilder(); mailMessage.AppendLine("<b>" + L("NameSurname") + "</b>: " + user.Name + " " + user.Surname + "<br />"); if (!tenancyName.IsNullOrEmpty()) { mailMessage.AppendLine("<b>" + L("TenancyName") + "</b>: " + tenancyName + "<br />"); } mailMessage.AppendLine("<b>" + L("UserName") + "</b>: " + user.UserName + "<br />"); if (!plainPassword.IsNullOrEmpty()) { mailMessage.AppendLine("<b>" + L("Password") + "</b>: " + plainPassword + "<br />"); } mailMessage.AppendLine("<br />"); mailMessage.AppendLine(L("EmailActivation_ClickTheLinkBelowToVerifyYourEmail") + "<br /><br />"); mailMessage.AppendLine("<a href=\"" + link + "\">" + link + "</a>"); emailTemplate.Replace("{EMAIL_BODY}", mailMessage.ToString()); await _emailSender.SendAsync(user.EmailAddress, L("EmailActivation_Subject"), emailTemplate.ToString()); }
public async Task GuiMailThongBaoBoSungHoSo(long hoSoId) { try { var hoso = await _hoSoRepos.GetAsync(hoSoId); var hosoxl = await _hoSoXuLyRepos.GetAsync(hoso.HoSoXuLyId_Active.Value); var subject = "Thông báo bổ sung hồ sơ"; var tenancyName = GetTenancyNameOrNull(_session.TenantId); var thuTucStr = CommonENum.GetEnumDescription((CommonENum.THU_TUC_TEXT)hoso.ThuTucId); var emailTemplate = new StringBuilder(_emailTemplateProvider.GetDefaultTemplate(_session.TenantId)); emailTemplate.Replace("{EMAIL_TITLE}", "Thông báo"); emailTemplate.Replace("{EMAIL_SUB_TITLE}", "Cục quản lý Y Dược cổ truyền Hà Nội thông báo"); var doanhNghiep = await _doanhNghiepRepos.GetAsync(hoso.DoanhNghiepId.Value); var link = _webUrlService.GetSiteRootAddress(tenancyName); var linkViewCongVan = _webUrlService.GetSiteRootAddress(tenancyName) + "File/GoToViewTaiLieu?url=" + hosoxl.DuongDanTepCA; var mailMessage = new StringBuilder(); mailMessage.AppendLine("<b>" + "Yêu cầu " + doanhNghiep.TenDoanhNghiep + " chỉnh sửa bổ sung hồ sơ " + hoso.MaHoSo + " của thủ tục " + thuTucStr + "</b>" + "<br />"); if (!String.IsNullOrEmpty(hosoxl.DuongDanTepCA)) { mailMessage.AppendLine("<b>" + "Nội dung yêu cầu bổ sung vui lòng xem chi tiết tại công văn yêu cầu bổ sung" + "</b>" + "<br />"); mailMessage.AppendLine("Click vào link phía dưới để xem công văn yêu cầu bổ sung" + "<br />"); mailMessage.AppendLine("<a href=\"" + linkViewCongVan + "\">" + linkViewCongVan + "</a>"); mailMessage.AppendLine("<br />"); } mailMessage.AppendLine("Click vào link phía dưới để đăng nhập vào hệ thống" + "<br />"); mailMessage.AppendLine("<a href=\"" + link + "\">" + link + "</a>"); emailTemplate.Replace("{EMAIL_BODY}", mailMessage.ToString()); await _emailSender.SendAsync(doanhNghiep.EmailDoanhNghiep, subject, emailTemplate.ToString()); } catch (Exception ex) { Logger.Error($"{DateTime.Now.ToString("HH:mm:ss dd/MM/yyyy")} GuiMailThongBaoBoSungHoSo {ex.Message} {JsonConvert.SerializeObject(ex)}"); } }
public async Task SendPasswordResetLinkAsync(User user, string link = null) { if (user.PasswordResetCode.IsNullOrEmpty()) { throw new Exception("PasswordResetCode should be set in order to send password reset link."); } var tenancyName = GetTenancyNameOrNull(user.TenantId); var emailTemplate = new StringBuilder(_emailTemplateProvider.GetDefaultTemplate(user.TenantId)); emailTemplate.Replace("{EMAIL_TITLE}", this.L("RecoverPassword")); emailTemplate.Replace("{EMAIL_SUB_TITLE}", this.L("RecoverPasswordSubtitle")); var mailMessage = new StringBuilder(); mailMessage.AppendLine("<b>" + L("NameSurname") + "</b>: " + user.Name + " " + user.Surname + "<br />"); if (!tenancyName.IsNullOrEmpty()) { mailMessage.AppendLine("<b>" + L("TenancyName") + "</b>: " + tenancyName + "<br />"); } mailMessage.AppendLine("<b>" + L("UserName") + "</b>: " + user.UserName + "<br />"); mailMessage.AppendLine("<b>" + L("ResetCode") + "</b>: " + user.PasswordResetCode + "<br />"); if (!link.IsNullOrEmpty()) { link = link.Replace("{userId}", user.Id.ToString()); link = link.Replace("{resetCode}", Uri.EscapeDataString(user.PasswordResetCode)); if (user.TenantId.HasValue) { link = link.Replace("{tenantId}", user.TenantId.ToString()); } mailMessage.AppendLine("<br />"); mailMessage.AppendLine(L("PasswordResetEmail_ClickTheLinkBelowToResetYourPassword") + "<br /><br />"); mailMessage.AppendLine("<a href=\"" + link + "\">" + link + "</a>"); } await ReplaceBodyAndSend(user.EmailAddress, L("PasswordResetEmail_Subject"), emailTemplate, mailMessage); }