コード例 #1
0
        /// <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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 /// <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));
 }
コード例 #5
0
 /// <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));
 }