Beispiel #1
0
        public static void Send(string subject, string toAddress, string template,
                                Dictionary <string, string> templateVariables, IEmailTemplateMethods emailTemplateMethods)
        {
            var client = new SmtpClient(Settings.SmtpHost, Settings.SmtpPort);

            client.Credentials = new NetworkCredential(Settings.SmtpUser, Settings.SmtpPassword);

            var from = new MailAddress(Settings.SmtpUser);

            var to = new MailAddress(toAddress);

            var message = new MailMessage(from, to);

            message.IsBodyHtml = true;

            var body = emailTemplateMethods.GetTemplate(template);

            foreach (var identifier in templateVariables.Keys)
            {
                if (body.Contains("{" + identifier + "}"))
                {
                    body = body.Replace("{" + identifier + "}", templateVariables[identifier]);
                }
            }

            message.Body            = body;
            message.BodyEncoding    = Encoding.UTF8;
            message.Subject         = subject;
            message.SubjectEncoding = Encoding.UTF8;

            client.Send(message);
        }
Beispiel #2
0
 public RegisterController(IUserMethods userMethods, IEmailTemplateMethods emailTemplateMethods)
 {
     _userMethods          = userMethods;
     _emailTemplateMethods = emailTemplateMethods;
 }
Beispiel #3
0
 public Users(IUserMethods userMethods, IEmailTemplateMethods emailTemplateMethods)
 {
     _userMethods          = userMethods;
     _emailTemplateMethods = emailTemplateMethods;
 }