コード例 #1
0
        public static void SendEmail(SendEmailInput input, Configuration config)
        {
            var email = SetupEmailMessage(input, config);

            using (var client = new SmtpClient(config.EmailHost, Convert.ToInt32(config.EmailPort)))
            {
                client.Credentials = new NetworkCredential(config.SmtpUsername, config.SmtpPassword);
                client.EnableSsl   = true;

                client.Send(email);
            }
        }
コード例 #2
0
        private bool IsValidRequest(SendEmailInput input, Configuration config)
        {
            if (string.IsNullOrEmpty(input.FromDomain) ||
                string.IsNullOrEmpty(input.Name) ||
                string.IsNullOrEmpty(input.Email) ||
                string.IsNullOrEmpty(input.Subject) ||
                string.IsNullOrEmpty(input.Message))
            {
                return(false);
            }

            return(config.ValidDomains
                   .Select(d => d.DomainName)
                   .Contains(input.FromDomain));
        }
コード例 #3
0
        private static MailMessage SetupEmailMessage(SendEmailInput input, Configuration config)
        {
            var email = new MailMessage
            {
                IsBodyHtml = true,
                From       = new MailAddress(config.FromEmail, config.FromName)
            };

            var sendToEmailAddress = config.ValidDomains
                                     .Single(d => d.DomainName == input.FromDomain).SendToEmail;

            email.To.Add(new MailAddress(sendToEmailAddress));
            email.ReplyToList.Add(input.Email);
            email.Subject = config.SubjectPrefix + input.Subject;
            email.Body    = $"<p>{input.Message}</p>";

            return(email);
        }
コード例 #4
0
        public SendEmailResponse SendEmail(SendEmailInput input)
        {
            var config         = new Configuration();
            var isValidRequest = IsValidRequest(input, config);

            if (isValidRequest)
            {
                EmailFacade.SendEmail(input, config);

                return(new SendEmailResponse
                {
                    IsRequestValid = true
                });
            }

            return(new SendEmailResponse
            {
                IsRequestValid = false
            });
        }