Beispiel #1
0
        public void SendMail(string from, string to, string messageType, IMessageBodyDictionary body)
        {
            var temp = templateProvider.GetTemplate(messageType);

            var content = contentBuilder.BuildContent(temp, body);

            //Create message
            var message = new MimeMessage();

            message.To.Add(new MailboxAddress(to));
            message.From.Add(new MailboxAddress(from));
            message.Body = new TextPart("html")
            {
                Text = content
            };

            var cred = credentialsProvider.GetCredentials();

            smtpClient.Connect(cred.Username, cred.Password);
            smtpClient.SendMessage(message);
            smtpClient.Diconnect();
        }
Beispiel #2
0
        public string BuildContent(string template, IMessageBodyDictionary body)
        {
            var matches = regex.Matches(template);
            var tmp     = template;

            foreach (var match in matches)
            {
                var matchS      = match.ToString();
                var replacement = body.GetReplacement(matchS);

                if (replacement == "")
                {
                    tmp = tmp.Remove(tmp.IndexOf(matchS), matchS.Length);
                }
                else
                {
                    tmp = tmp.Replace(matchS, body.GetReplacement(matchS));
                }
            }

            return(tmp);
        }