/// <summary> /// Prepares invitation e-mail message /// </summary> /// <returns></returns> protected MailMessage GetMessage() { EmailCreator emailCreator = GetEmailCreator(); EmailVariableSet emailCreatorParameters = new EmailVariableSet { Link = GetNotificationUrl(), GuestEmail = EmailTo, GuestName = UserName, FirstName = FirstName, LastName = LastName, OriginatorEmail = EmailFrom.Address, OriginatorName = EmailFrom.DisplayName, WorkroomName = WorkroomPage.WorkroomStartPage.PageName, GuestRole = Membership.TranslateMembershipLevel(MemberLevel) }; EmailSubject = emailCreator.GetSubject(emailCreatorParameters); EmailBody = emailCreator.GetBody(emailCreatorParameters); MailAddress toAddress = new MailAddress(EmailTo); MailMessage message = new MailMessage(EmailFrom, toAddress) { IsBodyHtml = true, Subject = EmailSubject, Body = EmailBody }; return(message); }
private static string GetPropertyValueFromSet(EmailVariableSet instance, string propertyName) { Type instanceType = instance.GetType(); Console.WriteLine(instanceType.Name); PropertyInfo propertyBanch = instanceType.GetProperty(propertyName); return(propertyBanch.GetValue(instance, null) as string); }
private static string UpdateTemplateWithValues(string rawString, EmailVariableSet variableSet) { Regex expression = new Regex(@"\[[\w]*\]"); MatchCollection matches = expression.Matches(rawString); string updatedString = rawString; foreach (Match match in matches) { string propertyValue = GetPropertyValueFromSet(variableSet, match.Value.Substring(1, match.Value.Length - 2)); updatedString = updatedString.Replace(match.Value, propertyValue); } return(updatedString); }
/// <summary> /// Returns a body string as the result of compilation a body property with values of variableSet instance. /// </summary> /// <param name="variableSet">A class with variables for replacement.</param> /// <returns>A compiled email subject string.</returns> public string GetBody(EmailVariableSet variableSet) { return(UpdateTemplateWithValues(EmailBody, variableSet)); }
/// <summary> /// Returns a subject string as the result of compilation a subject property with values of variableSet instance. /// </summary> /// <param name="variableSet">A class with variables for replacement.</param> /// <returns>A compiled email subject string.</returns> public string GetSubject(EmailVariableSet variableSet) { return(UpdateTemplateWithValues(EmailSubject, variableSet)); }