public string UpdateEmailTemplate(EmailTemplateForm emailTemplateForm) { DefaultController defaultController = new DefaultController(EmailTemplateService.Keywords.EMAILTEMPLATE); defaultController.FormValidator = new EmailTemplateFormValidator(); OperationResult result = defaultController.Update(emailTemplateForm); return(Serializer.Json.Serialize(result)); }
/// <summary> /// Gets the email template. Replacement parameters in the template are replaced with their appropriate values. The data /// in the template can be used to construct an e-mail. /// </summary> /// <param name="template">The template to retrieve.</param> /// <param name="user">The user associated with the template.</param> /// <returns>Returns an e-mail template.</returns> public static EmailTemplate GetEmailTemplate(EmailTemplateForm template, IUserAccount user) { EmailTemplate emailTemplate = new EmailTemplate(); emailTemplate.EmailTemplateId = template; string filePath = Utils.GetPath(String.Format(CultureInfo.InvariantCulture, "/templates/{0}.txt", template)); // Step 1: Get subject and body from text file and assign to fields. using (StreamReader sr = File.OpenText(filePath)) { while (sr.Peek() >= 0) { string lineText = sr.ReadLine().Trim(); if (lineText == "[Subject]") { emailTemplate.Subject = sr.ReadLine(); } if (lineText == "[Body]") { emailTemplate.Body = sr.ReadToEnd(); } } } // Step 2: Update replacement parameters with real values. emailTemplate.Body = emailTemplate.Body.Replace("{CurrentPageUrlFull}", Utils.GetCurrentPageUrlFull()); string userName = (user != null ? user.UserName : String.Empty); string email = (user != null ? user.Email : String.Empty); emailTemplate.Body = emailTemplate.Body.Replace("{UserName}", userName); emailTemplate.Body = emailTemplate.Body.Replace("{Email}", String.IsNullOrEmpty(email) ? Resources.GalleryServerPro.Email_Template_No_Email_For_User_Replacement_Text : email); if (emailTemplate.Body.Contains("{VerificationUrl}")) { emailTemplate.Body = emailTemplate.Body.Replace("{VerificationUrl}", GenerateVerificationLink(userName)); } if (emailTemplate.Body.Contains("{Password}")) { emailTemplate.Body = emailTemplate.Body.Replace("{Password}", UserController.GetPassword(userName)); } if (emailTemplate.Body.Contains("{ManageUserUrl}")) { emailTemplate.Body = emailTemplate.Body.Replace("{ManageUserUrl}", GenerateManageUserLink(userName)); } return(emailTemplate); }
/// <summary> /// Gets the email template. Replacement parameters in the template are replaced with their appropriate values. The data /// in the template can be used to construct an e-mail. /// </summary> /// <param name="template">The template to retrieve.</param> /// <param name="userName">The name of the user associated with the template.</param> /// <param name="email">The email of the user associated with the template.</param> /// <returns>Returns an e-mail template.</returns> private EmailTemplate GetEmailTemplate(EmailTemplateForm template, string userName, string email) { EmailTemplate emailTemplate = new EmailTemplate(); emailTemplate.EmailTemplateId = template; //string filePath = Utils.GetPath(String.Format(CultureInfo.InvariantCulture, "/templates/{0}.txt", template)); var filePath = $"{_env.ContentRootPath}/templates/{template}.txt"; // Step 1: Get subject and body from text file and assign to fields. using (StreamReader sr = File.OpenText(filePath)) { while (sr.Peek() >= 0) { string lineText = sr.ReadLine().Trim(); if (lineText == "[Subject]") { emailTemplate.Subject = sr.ReadLine(); } if (lineText == "[Body]") { emailTemplate.Body = sr.ReadToEnd(); } } } // Step 2: Update replacement parameters with real values. emailTemplate.Body = emailTemplate.Body.Replace("{CurrentPageUrlFull}", _urlController.GetAppUrl()); emailTemplate.Body = emailTemplate.Body.Replace("{UserName}", userName); emailTemplate.Body = emailTemplate.Body.Replace("{Email}", String.IsNullOrEmpty(email) ? "<no e-mail>" : email); if (emailTemplate.Body.Contains("{VerificationUrl}")) { emailTemplate.Body = emailTemplate.Body.Replace("{VerificationUrl}", GenerateVerificationLink(userName)); } if (emailTemplate.Body.Contains("{Password}")) { throw new NotImplementedException(); } //emailTemplate.Body = emailTemplate.Body.Replace("{Password}", UserController.GetPassword(userName)); if (emailTemplate.Body.Contains("{ManageUserUrl}")) { emailTemplate.Body = emailTemplate.Body.Replace("{ManageUserUrl}", GenerateManageUserLink(userName)); } return(emailTemplate); }
/// <summary> /// Sends an e-mail based on the <paramref name="templateForm"/> to the specified <paramref name="user"/>. /// No action is taken if the user's e-mail is null or empty. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). If <paramref name="sendOnBackgroundThread"/> is true, the e-mail is sent on a background /// thread and the function returns immediately. An exception is thrown if an error occurs while sending the e-mail, /// unless <paramref name="sendOnBackgroundThread"/> is true, in which case the error is logged but the exception does /// not propagate back to the UI thread. /// </summary> /// <param name="user">The user to receive the e-mail.</param> /// <param name="templateForm">The template form specifying the type of e-mail to send.</param> /// <param name="galleryId">The gallery ID containing the e-mail configuration settings to use.</param> /// <param name="sendOnBackgroundThread">If set to <c>true</c> send e-mail on a background thread. This causes any errors /// to be silently handled by the error logging system, so if it is important for any errors to propogate to the UI, /// such as when testing the e-mail function in the Site Administration area, set to <c>false</c>.</param> public static void SendNotificationEmail(IUserAccount user, EmailTemplateForm templateForm, int galleryId, bool sendOnBackgroundThread) { if (String.IsNullOrEmpty(user.Email)) { return; } EmailTemplate emailTemplate = GetEmailTemplate(templateForm, user); MailAddress emailRecipient = new MailAddress(user.Email, user.UserName); SendEmail(emailRecipient, emailTemplate.Subject, emailTemplate.Body, galleryId, sendOnBackgroundThread); }
public OperationResult SendEmailByTag(SendEmailForm sendEmailForm) { SenderEmailAccountForm senderEmailAccount = GetSenderEmailAccountByTag(sendEmailForm.Tag); EmailTemplateForm emailTemplate = GetEmailTemplateByTag(sendEmailForm.Tag); if (senderEmailAccount != null && emailTemplate != null) { emailTemplate.EmailContent = ReplaceContent(emailTemplate.EmailContent, sendEmailForm.KeyValues); emailTemplate.EmailSubject = ReplaceContent(emailTemplate.EmailSubject, sendEmailForm.KeyValues); return(SaveToDatabase(senderEmailAccount, emailTemplate, sendEmailForm)); } return(new OperationResult(false, "No sender and email template defined for tag = '" + sendEmailForm.Tag + "'")); }
protected virtual EmailTemplateForm GetEmailTemplateByTag(string tag) { IEmailTemplateBusinessService emailTemplateBusinessService = new EmailTemplateBusinessService(); OperationResult result = emailTemplateBusinessService.FindAllByTag(tag); List <object> emailTemplateList = (List <object>)result.Data; if (emailTemplateList.Count > 0) { object obj = emailTemplateList[0]; EmailTemplateForm emailTemplateForm = new EmailTemplateForm(); EmailTemplateFormDataConverter converter = new EmailTemplateFormDataConverter(); converter.PopulateForm(obj, emailTemplateForm); return(emailTemplateForm); } return(null); }
/// <summary> /// Sends an e-mail based on the <paramref name="templateForm" /> to the <paramref name="userName" /> having the /// <paramref name="email" />. No action is taken if the user's e-mail is null or empty. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). If <paramref name="sendOnBackgroundThread" /> is true, the e-mail is sent on a background /// thread and the function returns immediately. An exception is thrown if an error occurs while sending the e-mail, /// unless <paramref name="sendOnBackgroundThread" /> is true, in which case the error is logged but the exception does /// not propagate back to the UI thread. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="email">The email address of the user.</param> /// <param name="templateForm">The template form specifying the type of e-mail to send.</param> /// <param name="sendOnBackgroundThread">If set to <c>true</c> send e-mail on a background thread. This causes any errors /// to be silently handled by the error logging system, so if it is important for any errors to propogate to the UI, /// such as when testing the e-mail function in the Site Administration area, set to <c>false</c>.</param> /// <exception cref="System.ArgumentNullException">userName</exception> /// <exception cref="ArgumentNullException">Thrown when <paramref name="userName" /> is null.</exception> public void SendNotificationEmail(string userName, string email, EmailTemplateForm templateForm, bool sendOnBackgroundThread) { if (userName == null) { throw new ArgumentNullException("userName"); } if (String.IsNullOrEmpty(email)) { return; } EmailTemplate emailTemplate = GetEmailTemplate(templateForm, userName, email); MailAddress emailRecipient = new MailAddress(email, userName); SendEmail(emailRecipient, emailTemplate.Subject, emailTemplate.Body, sendOnBackgroundThread); }
public ValidationResult Validate(DataForm form) { ValidationResult result = new ValidationResult(true); EmailTemplateForm emailTemplateForm = (EmailTemplateForm)form; if (emailTemplateForm.EmailSubject.Length == 0) { result.Result = false; result.ErrorMessage = "Email Subject can not be empty"; } if (emailTemplateForm.Tag.Length == 0) { result.Result = false; result.ErrorMessage = "Tag can not be empty"; } return(result); }
/// <summary> /// Gets the email template. Replacement parameters in the template are replaced with their appropriate values. The data /// in the template can be used to construct an e-mail. /// </summary> /// <param name="template">The template to retrieve.</param> /// <param name="user">The user associated with the template.</param> /// <returns>Returns an e-mail template.</returns> public static EmailTemplate GetEmailTemplate(EmailTemplateForm template, IUserAccount user) { EmailTemplate emailTemplate = new EmailTemplate(); emailTemplate.EmailTemplateId = template; string filePath = Utils.GetPath(String.Format(CultureInfo.InvariantCulture, "/templates/{0}.txt", template)); // Step 1: Get subject and body from text file and assign to fields. using (StreamReader sr = File.OpenText(filePath)) { while (sr.Peek() >= 0) { string lineText = sr.ReadLine().Trim(); if (lineText == "[Subject]") emailTemplate.Subject = sr.ReadLine(); if (lineText == "[Body]") emailTemplate.Body = sr.ReadToEnd(); } } // Step 2: Update replacement parameters with real values. emailTemplate.Body = emailTemplate.Body.Replace("{CurrentPageUrlFull}", Utils.GetCurrentPageUrlFull()); string userName = (user != null ? user.UserName : String.Empty); string email = (user != null ? user.Email : String.Empty); emailTemplate.Body = emailTemplate.Body.Replace("{UserName}", userName); emailTemplate.Body = emailTemplate.Body.Replace("{Email}", String.IsNullOrEmpty(email) ? Resources.GalleryServerPro.Email_Template_No_Email_For_User_Replacement_Text : email); if (emailTemplate.Body.Contains("{VerificationUrl}")) emailTemplate.Body = emailTemplate.Body.Replace("{VerificationUrl}", GenerateVerificationLink(userName)); if (emailTemplate.Body.Contains("{Password}")) emailTemplate.Body = emailTemplate.Body.Replace("{Password}", UserController.GetPassword(userName)); if (emailTemplate.Body.Contains("{ManageUserUrl}")) emailTemplate.Body = emailTemplate.Body.Replace("{ManageUserUrl}", GenerateManageUserLink(userName)); return emailTemplate; }
/// <summary> /// Sends an e-mail based on the <paramref name="templateForm"/> to the specified <paramref name="user"/>. /// No action is taken if the user's e-mail is null or empty. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). /// </summary> /// <param name="user">The user to receive the e-mail.</param> /// <param name="templateForm">The template form specifying the type of e-mail to send.</param> public void SendNotificationEmail(IUserAccount user, EmailTemplateForm templateForm) { SendNotificationEmail(user.UserName, user.Email, templateForm, true); }
/// <summary> /// Sends an e-mail based on the <paramref name="templateForm" /> to the <paramref name="userName" /> having the /// <paramref name="email" />. No action is taken if the user's e-mail is null or empty. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). If <paramref name="sendOnBackgroundThread" /> is true, the e-mail is sent on a background /// thread and the function returns immediately. An exception is thrown if an error occurs while sending the e-mail, /// unless <paramref name="sendOnBackgroundThread" /> is true, in which case the error is logged but the exception does /// not propagate back to the UI thread. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="email">The email address of the user.</param> /// <param name="templateForm">The template form specifying the type of e-mail to send.</param> /// <param name="sendOnBackgroundThread">If set to <c>true</c> send e-mail on a background thread. This causes any errors /// to be silently handled by the error logging system, so if it is important for any errors to propogate to the UI, /// such as when testing the e-mail function in the Site Administration area, set to <c>false</c>.</param> /// <exception cref="System.ArgumentNullException">userName</exception> /// <exception cref="ArgumentNullException">Thrown when <paramref name="userName" /> is null.</exception> public static void SendNotificationEmail(string userName, string email, EmailTemplateForm templateForm, bool sendOnBackgroundThread) { if (userName == null) throw new ArgumentNullException("userName"); if (String.IsNullOrEmpty(email)) return; EmailTemplate emailTemplate = GetEmailTemplate(templateForm, userName, email); MailAddress emailRecipient = new MailAddress(email, userName); SendEmail(emailRecipient, emailTemplate.Subject, emailTemplate.Body, sendOnBackgroundThread); }
/// <overloads> /// Gets the email template. /// </overloads> /// <summary> /// Gets the email template. Replacement parameters in the template are replaced with their appropriate values. The data /// in the template can be used to construct an e-mail. /// </summary> /// <param name="template">The template to retrieve.</param> /// <param name="user">The user associated with the template.</param> /// <returns>Returns an e-mail template.</returns> public EmailTemplate GetEmailTemplate(EmailTemplateForm template, IUserAccount user) { return(GetEmailTemplate(template, user.UserName, user.Email)); }
/// <summary> /// Sends an e-mail based on the <paramref name="templateForm"/> to the specified <paramref name="user"/>. /// No action is taken if the user's e-mail is null or empty. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). If <paramref name="sendOnBackgroundThread"/> is true, the e-mail is sent on a background /// thread and the function returns immediately. An exception is thrown if an error occurs while sending the e-mail, /// unless <paramref name="sendOnBackgroundThread"/> is true, in which case the error is logged but the exception does /// not propagate back to the UI thread. /// </summary> /// <param name="user">The user to receive the e-mail.</param> /// <param name="templateForm">The template form specifying the type of e-mail to send.</param> /// <param name="sendOnBackgroundThread">If set to <c>true</c> send e-mail on a background thread. This causes any errors /// to be silently handled by the error logging system, so if it is important for any errors to propogate to the UI, /// such as when testing the e-mail function in the Site Administration area, set to <c>false</c>.</param> public static void SendNotificationEmail(UserEntity user, EmailTemplateForm templateForm, bool sendOnBackgroundThread) { if (String.IsNullOrEmpty(user.Email)) return; EmailTemplate emailTemplate = GetEmailTemplate(templateForm, user); MailAddress emailRecipient = new MailAddress(user.Email, user.UserName); SendEmail(emailRecipient, emailTemplate.Subject, emailTemplate.Body, sendOnBackgroundThread); }
/// <summary> /// Sends an e-mail based on the <paramref name="templateForm"/> to the specified <paramref name="user"/>. /// No action is taken if the user's e-mail is null or empty. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). /// </summary> /// <param name="user">The user to receive the e-mail.</param> /// <param name="templateForm">The template form specifying the type of e-mail to send.</param> public static void SendNotificationEmail(UserEntity user, EmailTemplateForm templateForm) { SendNotificationEmail(user, templateForm, true); }
/// <summary> /// Sends an e-mail based on the <paramref name="templateForm"/> to the specified <paramref name="user"/>. /// No action is taken if the user's e-mail is null or empty. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). /// </summary> /// <param name="user">The user to receive the e-mail.</param> /// <param name="templateForm">The template form specifying the type of e-mail to send.</param> /// <param name="galleryId">The gallery ID.</param> public static void SendNotificationEmail(IUserAccount user, EmailTemplateForm templateForm, int galleryId) { SendNotificationEmail(user, templateForm, galleryId, true); }
/// <overloads> /// Gets the email template. /// </overloads> /// <summary> /// Gets the email template. Replacement parameters in the template are replaced with their appropriate values. The data /// in the template can be used to construct an e-mail. /// </summary> /// <param name="template">The template to retrieve.</param> /// <param name="user">The user associated with the template.</param> /// <returns>Returns an e-mail template.</returns> public static EmailTemplate GetEmailTemplate(EmailTemplateForm template, IUserAccount user) { return GetEmailTemplate(template, user.UserName, user.Email); }
protected virtual OperationResult SaveToDatabase(SenderEmailAccountForm senderEmailAccount, EmailTemplateForm emailTemplate, SendEmailForm sendMailForm) { object obj = Factory.Create <object>("EmailSent", ClassType.clsTypeDataModel); obj.GetType().GetProperty("SenderName").SetValue(obj, senderEmailAccount.SenderName, null); obj.GetType().GetProperty("EmailFrom").SetValue(obj, senderEmailAccount.EmailAccount, null); obj.GetType().GetProperty("EmailFromAlias").SetValue(obj, senderEmailAccount.SenderEmail, null); obj.GetType().GetProperty("EmailSubject").SetValue(obj, emailTemplate.EmailSubject, null); obj.GetType().GetProperty("EmailContent").SetValue(obj, emailTemplate.EmailContent, null); obj.GetType().GetProperty("SentDate").SetValue(obj, DateTime.Now, null); obj.GetType().GetProperty("EmailTos").SetValue(obj, sendMailForm.To, null); obj.GetType().GetProperty("EmailCcs").SetValue(obj, sendMailForm.Cc, null); obj.GetType().GetProperty("UserId").SetValue(obj, senderEmailAccount.UserId, null); obj.GetType().GetProperty("IsSent").SetValue(obj, 0, null); obj.GetType().GetProperty("EmailAccountId").SetValue(obj, senderEmailAccount.IdSender, null); EmailSentBusinessService businessService = new EmailSentBusinessService(); OperationResult result = businessService.Add(obj); object emailSent = result.Data; EmailAttachmentBusinessService bs = new EmailAttachmentBusinessService(); if (sendMailForm.Attachments != null) { foreach (EmailAttachment attachment in sendMailForm.Attachments) { attachment.EmailSentId = Convert.ToInt64(emailSent.GetType().GetProperty("IdEmailSent").GetValue(emailSent, null)); bs.Add(attachment); } } // emailSent.EmailContent = Convert.ToBase64String(Encoding.UTF8.GetBytes(emailSent.EmailContent)); result.Data = emailSent; return(result); }
/// <summary> /// Sends an e-mail based on the <paramref name="templateForm"/> to the specified <paramref name="user"/>. /// No action is taken if the user's e-mail is null or empty. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). /// </summary> /// <param name="user">The user to receive the e-mail.</param> /// <param name="templateForm">The template form specifying the type of e-mail to send.</param> public static void SendNotificationEmail(IUserAccount user, EmailTemplateForm templateForm) { SendNotificationEmail(user.UserName, user.Email, templateForm, true); }
/// <summary> /// Sends an e-mail based on the <paramref name="templateForm"/> to the specified <paramref name="user"/>. /// No action is taken if the user's e-mail is null or empty. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). /// </summary> /// <param name="user">The user to receive the e-mail.</param> /// <param name="templateForm">The template form specifying the type of e-mail to send.</param> public static void SendNotificationEmail(UserEntity user, EmailTemplateForm templateForm) { SendNotificationEmail(user, templateForm, true); }
/// <summary> /// Sends an e-mail based on the <paramref name="templateForm"/> to the specified <paramref name="user"/>. /// No action is taken if the user's e-mail is null or empty. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). If <paramref name="sendOnBackgroundThread"/> is true, the e-mail is sent on a background /// thread and the function returns immediately. An exception is thrown if an error occurs while sending the e-mail, /// unless <paramref name="sendOnBackgroundThread"/> is true, in which case the error is logged but the exception does /// not propagate back to the UI thread. /// </summary> /// <param name="user">The user to receive the e-mail.</param> /// <param name="templateForm">The template form specifying the type of e-mail to send.</param> /// <param name="galleryId">The gallery ID containing the e-mail configuration settings to use.</param> /// <param name="sendOnBackgroundThread">If set to <c>true</c> send e-mail on a background thread. This causes any errors /// to be silently handled by the error logging system, so if it is important for any errors to propogate to the UI, /// such as when testing the e-mail function in the Site Administration area, set to <c>false</c>.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="user" /> is null.</exception> public static void SendNotificationEmail(IUserAccount user, EmailTemplateForm templateForm, int galleryId, bool sendOnBackgroundThread) { if (user == null) throw new ArgumentNullException("user"); if (String.IsNullOrEmpty(user.Email)) return; EmailTemplate emailTemplate = GetEmailTemplate(templateForm, user); MailAddress emailRecipient = new MailAddress(user.Email, user.UserName); SendEmail(emailRecipient, emailTemplate.Subject, emailTemplate.Body, galleryId, sendOnBackgroundThread); }
/// <summary> /// Sends an e-mail based on the <paramref name="templateForm"/> to the specified <paramref name="user"/>. /// No action is taken if the user's e-mail is null or empty. The e-mail is sent on a /// background thread, so if an error occurs on that thread no exception bubbles to the caller (the error, however, is /// recorded in the error log). /// </summary> /// <param name="user">The user to receive the e-mail.</param> /// <param name="templateForm">The template form specifying the type of e-mail to send.</param> /// <param name="galleryId">The gallery ID.</param> public static void SendNotificationEmail(IUserAccount user, EmailTemplateForm templateForm, int galleryId) { SendNotificationEmail(user, templateForm, galleryId, true); }