public EmailTemplateModel(EmailTemplateId templateId, string subj, string html, string text) { this.TemplateId = templateId; this.Subject = subj; this.Html = html; this.Text = text; }
public override int GetHashCode() { var hashCode = 1296822809; hashCode = hashCode * -1521134295 + EmailTemplateId.GetHashCode(); hashCode = hashCode * -1521134295 + PartId.GetHashCode(); return(hashCode); }
private async Task EnqueueEmail(EmailTemplateId id, string recipient, IReadOnlyDictionary <string, string> fields, params IEntity[] entities) { var template = await emailRepository.GetEmailTemplateAsync(id); Email email = template.CreateEmail(recipient, fields, entities); emailRepository.Add(email); await UnitOfWork.SaveAsync(); }
public async Task <ResponseModel> ProcessTemplate(Guid userId, EmailTemplateId templateId, string to, Dictionary <string, string> parameters, params object[] items) { if (TryProcessTemplate(out EmailTemplateProcessor p, templateId, parameters, items)) { SendEmailModel sem = new SendEmailModel(userId, to, p.Template.Subject, p.Template.Text); return(await this.DataManager.SendEmail(sem)); } else { return(ResponseModel.Error(ResponseCode.Internal_UnhandledError, string.Join(Environment.NewLine, p.Errors))); } }
public Task <EmailTemplate> GetEmailTemplateAsync(EmailTemplateId id) { return(Context.EmailTemplates.FirstAsync(e => e.Id == (int)id)); }
public EmailTemplateModel GetEmailTemplate(EmailTemplateId id) => _emailTemplates.TryGetValue(id, out EmailTemplateModel item) ? item : null;
public async Task <ResponseModel> ProcessTemplate(Guid userId, EmailTemplateId templateId, string to, params object[] items) => await ProcessTemplate(userId, templateId, to, null, items);
public bool TryProcessTemplate(out EmailTemplateProcessor processor, EmailTemplateId templateId, Dictionary <string, string> parameters, params object[] items) { var t = this.DataManager.GetEmailTemplate(templateId); processor = null; if (t == null) { processor = new EmailTemplateProcessor("No template found for: " + templateId.ToString()); } else { var url = this.BaseUrl(); if (parameters == null) { parameters = new Dictionary <string, string>(); } UserModel user = null; if (items != null && items.Length > 0) { user = items.FirstOrDefault(c => c is UserModel) as UserModel; } //DisplayName is used in emails as a safety valve to identify who the user is... if (user != null) { parameters.TryAdd("DisplayName", user.Name ?? string.Empty); } else { parameters.TryAdd("DisplayName", ""); } parameters.TryAdd("HomeUrl", url); parameters.TryAdd("LoginUrl", url + "login"); parameters.TryAdd("SignupUrl", url + "signup"); parameters.TryAdd("LogoUrl", url + "statics/logo.png"); parameters.TryAdd("PhishingUrl", url + "phishing"); //get the html containing the master layout for all emails //string layout = string.Copy( this.DataManager.EmailLayout.Text ); //processor = new EmailTemplateProcessor( t, layout, parameters, items ); processor = new EmailTemplateProcessor(t, parameters, items); //var matches = Regex.Matches("Test {Token1} {Token 2}", @"{([^{}]*)"); var regex = new System.Text.RegularExpressions.Regex(@"{([^{}]*)", System.Text.RegularExpressions.RegexOptions.Multiline); try { TemplateParameterDiscoverer(regex.Match(processor.Template.Subject), processor.SubjParameters); } catch (Exception ex) { processor.AddError("Error parsing subject parameters: " + ex.ToString()); } try { TemplateParameterDiscoverer(regex.Match(processor.Template.Text), processor.BodyParameters); } catch (Exception ex) { processor.AddError("Error parsing html parameters: " + ex.ToString()); } try { TemplateParameterPopulator(processor); } catch (Exception ex) { processor.AddError("Error populating parameters: " + ex.ToString()); } } return(processor.Successful); }
public EmailTemplate(EmailTemplateId id, string subject, string body) : this((int)id, subject, body) { }