public void GivenSendEmailEventHandler_WhenEmailIsReceived_ThenShouldCallEmailSender()
        {
            var emailToSend     = new Email();
            var sendEmailEvent  = new SendEmailEvent(emailToSend);
            var mockEmailSender = Substitute.For <IEmailSender>();

            var sendEmailEventHandler = new SendEmailEventHandler(mockEmailSender);

            sendEmailEventHandler.Handle(sendEmailEvent);

            mockEmailSender.Received().SendEmail(emailToSend);
        }
Beispiel #2
0
        public void MailSendWithoutToAddressTest()
        {
            var         obj         = _isMptpClient.Object;
            MailMessage mailMessage = new MailMessage();

            _iConfiguration.Setup(c => c.GetSection(It.IsAny <String>())).Returns(new Mock <IConfigurationSection>().Object);
            SendEmailEvent sendEmailEvent = new SendEmailEvent();

            sendEmailEvent.Body    = "test";
            sendEmailEvent.Subject = "test";

            IMailService mailService = new MailService(_isMptpClient.Object, _iConfiguration.Object);

            Assert.Throws <ArgumentNullException>(() => mailService.Execute(sendEmailEvent));
        }
Beispiel #3
0
        public void MailSendTest()
        {
            var         obj         = _isMptpClient.Object;
            MailMessage mailMessage = new MailMessage();

            _iConfiguration.Setup(c => c.GetSection(It.IsAny <String>())).Returns(new Mock <IConfigurationSection>().Object);
            SendEmailEvent sendEmailEvent = new SendEmailEvent();

            sendEmailEvent.Body      = "test";
            sendEmailEvent.Subject   = "test";
            sendEmailEvent.ToAddress = new System.Collections.Generic.List <string> {
                "*****@*****.**"
            };
            IMailService mailService = new MailService(_isMptpClient.Object, _iConfiguration.Object);

            mailService.Execute(sendEmailEvent);
        }
        public void SendMail(EmailDto emailInputs)
        {
            _logger.LogInformation($"SendMail method hit");
            _logger.LogInformation($"Channel Key: {emailInputs.ChannelKey} , Template Name: {emailInputs.TemplateName}, Variant: {emailInputs.Variant}, Recipients: {emailInputs.Recipients}, Sender: {emailInputs.Sender}.");
            //string user = (!string.IsNullOrEmpty(emailInputs.Username) ? emailInputs.Username : emailInputs.Recipients);
            var sendEmailEvent = new SendEmailEvent();

            sendEmailEvent.ChannelKey   = emailInputs.ChannelKey;
            sendEmailEvent.TemplateName = emailInputs.TemplateName;
            sendEmailEvent.Variant      = emailInputs.Variant;
            sendEmailEvent.Sender       = emailInputs.Sender;
            sendEmailEvent.Recipients   = emailInputs.Recipients;
            sendEmailEvent.Subject      = emailInputs.Subject;
            sendEmailEvent.MessageParts = emailInputs.MessageParts;
            sendEmailEvent.Tag          = emailInputs.Tag;
            _logger.LogInformation("Publishing Email data.");
            _eventBus.Publish(sendEmailEvent);
        }
Beispiel #5
0
        public IEvent CreateEvent(string exchange)
        {
            IEvent ev;

            if (exchange == EventType.SendEmail.ToString())
            {
                ev = new SendEmailEvent();
            }

            else if (exchange == EventType.SendSms.ToString())
            {
                ev = new SendSmsEvent();
            }

            else
            {
                throw new EventNotSupportedException(exchange);
            }

            return(ev);
        }
Beispiel #6
0
        public void Execute(SendEmailEvent sendEmailEvent)
        {
            var mailMessage = new MailMessage
            {
                From = new MailAddress(_configuration.GetValue <string>("SmtpUsername", "*****@*****.**"))
            };

            if (sendEmailEvent.ToAddress != null)
            {
                foreach (var toAddress in sendEmailEvent.ToAddress)
                {
                    mailMessage.To.Add(toAddress);
                }
            }
            else
            {
                throw new ArgumentNullException("To Address can't be blank");
            }

            if (sendEmailEvent.BccAddress != null)
            {
                foreach (var bccAddress in sendEmailEvent.BccAddress)
                {
                    mailMessage.Bcc.Add(bccAddress);
                }
            }
            if (sendEmailEvent.CCAddress != null)
            {
                foreach (var ccAddress in sendEmailEvent.CCAddress)
                {
                    mailMessage.Bcc.Add(ccAddress);
                }
            }

            mailMessage.Body       = sendEmailEvent.Body;
            mailMessage.Subject    = sendEmailEvent.Subject;
            mailMessage.IsBodyHtml = true;
            _smtpClient.EnableSSLForEmail();
            _smtpClient.Send(mailMessage);
        }
 //event bus handler mock for subscribed event SendEmail
 public async Task Handle(SendEmailEvent eventMessage)
 {
     _messageRoutingService.RouteEmail(eventMessage.Email);
 }