Exemple #1
0
        /// <summary>
        /// Send the Email Notification
        /// </summary>
        public void Send()
        {
            _log.Info("Sending Email...");

            // Create the Email
            var mail = new MailMessage
            {
                From       = new MailAddress(SmtpConfiguration.Email, SmtpConfiguration.DisplayName),
                Subject    = Subject,
                Body       = Body,
                IsBodyHtml = true
            };

            // Add any attachments
            if (_attachments != null)
            {
                _attachments.ForEach(mail.Attachments.Add);
            }

            // Add Recipients
            foreach (var to in ToEmailAddresses.Where(RegexUtilities.IsValidEmail))
            {
                mail.To.Add(to);
            }
            foreach (var cc in CcEmailAddresses.Where(RegexUtilities.IsValidEmail))
            {
                mail.CC.Add(cc);
            }
            foreach (var bcc in BccEmailAddresses.Where(RegexUtilities.IsValidEmail))
            {
                mail.Bcc.Add(bcc);
            }

            // Create the SMTP Client
            var client = new SmtpClient
            {
                Host                  = SmtpConfiguration.ServerName,
                Port                  = SmtpConfiguration.Port,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                EnableSsl             = SmtpConfiguration.EnableSsl,
                Credentials           = new NetworkCredential(SmtpConfiguration.UserName, SmtpConfiguration.Password)
            };

            try
            {
                // Send the Email
                client.Send(mail);
            }
            catch (Exception inner)
            {
                var ex = new Exception("Failure sending Email Notification.", inner);
                _log.Error(ex);
                throw ex;
            }
            finally
            {
                // Cleanup
                DisposeAttachments();
                mail.Dispose();
                client.Dispose();
            }
        }
Exemple #2
0
        public override async Task <ExecutionResult> RunAsync(IStepExecutionContext context)
        {
            if (EmailAddresses == null)
            {
                EmailAddresses = new List <string>();
            }
            if (CcEmailAddresses == null)
            {
                CcEmailAddresses = new List <string>();
            }
            if (BccEmailAddresses == null)
            {
                BccEmailAddresses = new List <string>();
            }
            //_logger.LogInformation("STEP: SendEmail");
            //var x = _emailSender.SendEmailAsync(EmailAddresses.ToArray(), CcEmailAddresses.ToArray(), BccEmailAddresses.ToArray(), EmailSubject, EmailMessage, IsBodyHtml, MailPriority);
            Task.Run(() =>
                     _emailSender.SendEmailAsync(EmailAddresses.ToArray(), CcEmailAddresses.ToArray(), BccEmailAddresses.ToArray(), EmailSubject, EmailMessage, true, MailPriority));

            return(ExecutionResult.Next());
        }