Example #1
0
 public async Task SendMailMessageAsynchronously()
 {
     var mailProvider = MailProviderFactory.GetProvider();
     await mailProvider.SendAsync(new MailMessage("*****@*****.**", "*****@*****.**")
     {
         Subject = "Some subject",
         Body    = "Some message"
     });
 }
Example #2
0
        public void SendMailMessage()
        {
            var mailProvider = MailProviderFactory.GetProvider();

            mailProvider.Send(new MailMessage("*****@*****.**", "*****@*****.**")
            {
                Subject = "Some subject",
                Body    = "Some message"
            });
        }
Example #3
0
        /// <summary>
        /// Asynschronously sends an email to a user.
        /// </summary>
        /// <param name="message">The message to send.</param>
        /// <returns>The task representing the asynchronous operation.</returns>
        public Task SendAsync(IdentityMessage message)
        {
            var mailProvider = MailProviderFactory.GetProvider();
            var mail         = new MailMessage();

            mail.To.Add(message.Destination);
            mail.Subject = message.Subject;
            mail.Body    = message.Body;

            return(mailProvider.SendAsync(mail));
        }
        public void ShouldThrowWhenInvalidNumberIsGiven()
        {
            // Arrange

            var mapper        = Substitute.For <IMapper>();
            var configuration = Substitute.For <IConfigurationLoader>();

            configuration.GetConfiguration().Returns(new Dictionary <string, string>());
            var factory = new MailProviderFactory();

            // Act / Assert

            Should.Throw <ArgumentOutOfRangeException>(() => factory.GetProvider(configuration, mapper, (Provider)100));
        }
        public void ShouldThrowWhenMailProviderKeyDoesNotExist()
        {
            // Arrange

            var mapper        = Substitute.For <IMapper>();
            var configuration = Substitute.For <IConfigurationLoader>();

            configuration.GetConfiguration().Returns(new Dictionary <string, string>());

            var factory = new MailProviderFactory();

            // Act / Assert

            Should.Throw <InvalidOperationException>(() => factory.GetProvider(configuration, mapper));
        }
        public void ShouldThrowWhenUnknownProviderIsGiven()
        {
            // Arrange

            var mapper        = Substitute.For <IMapper>();
            var configuration = Substitute.For <IConfigurationLoader>();

            configuration.GetConfiguration().Returns(new Dictionary <string, string>()
            {
                { "MailProvider", "NotARealProvider" }
            });

            var factory = new MailProviderFactory();

            // Act / Assert

            Should.Throw <ArgumentException>(() => factory.GetProvider(configuration, mapper));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            // Composition root.

            IMailProviderFactory factory       = new MailProviderFactory();
            IConfigurationLoader configuration = new ConfigurationLoader();
            IMapper mapper = null;

            var config = configuration.GetConfiguration();

            if (!config.ContainsKey("MailProvider"))
            {
                return(req.CreateErrorResponse(HttpStatusCode.InternalServerError, "Mail Provider not configured."));
            }

            log.Info($"Using \"{configuration.GetConfiguration()["MailProvider"]}\" provider.");
            var provider = factory.GetProvider(configuration, mapper);

            return(req.CreateResponse(HttpStatusCode.OK));
        }
Example #8
0
        public void OkCommand(object ownerWindow)
        {
            MailProviderFactory emailFactory = null;

            switch (_selectedReceiveConfiguration.Protocol)
            {
            case EmailProtocolType.Imap:
                emailFactory = new ImapProviderFactory();
                break;

            case EmailProtocolType.Pop3:
                emailFactory = new Pop3ProviderFactory();
                break;

            default:
                break;
            }

            MailConnection connection = emailFactory.CreateConnection();

            connection.Host = _selectedReceiveConfiguration.Host;
            connection.IsSslAuthentication = _selectedReceiveConfiguration.IsSslAuthentication;
            connection.Port = _selectedReceiveConfiguration.Port;
            ////connection.Open();
            SslMailConnectionDecorator sslMailConnectionDecorator = new SslMailConnectionDecorator();

            sslMailConnectionDecorator.MailConnection = connection;
            sslMailConnectionDecorator.Open();
            MailClient client = emailFactory.CreateClient();

            client.Authenticate(new MailUserInfo()
            {
                Email = _login, Password = _securePassword
            });

            new MainWindow()
            {
                DataContext = new MainWindowVM(client)
            }.Show();
            ((Window)ownerWindow).Close();
        }
Example #9
0
        public void SetUp()
        {
            mockProvider1.Setup(x => x.AssociatedMailTypes)
            .Returns(new List <MessageType> {
                MessageType.LostPasswordMail
            });
            mockProvider2.Setup(x => x.AssociatedMailTypes)
            .Returns(new List <MessageType> {
                MessageType.OrderMail
            });
            mockProvider3.Setup(x => x.AssociatedMailTypes)
            .Returns(new List <MessageType> {
                MessageType.ShipmentMail
            });

            factory = new MailProviderFactory(new List <ISendMail>
            {
                mockProvider1.Object,
                mockProvider2.Object,
                mockProvider3.Object
            });
        }
        public void ShouldReturnCorrectProvider()
        {
            // Arrange

            var mapper        = Substitute.For <IMapper>();
            var configuration = Substitute.For <IConfigurationLoader>();

            configuration.GetConfiguration().Returns(new Dictionary <string, string>()
            {
                { "MailProvider", "SendGrid" }
            });

            var factory = new MailProviderFactory();

            // Act

            var provider = factory.GetProvider(configuration, mapper);

            // Assert

            provider.ShouldNotBeNull();
            provider.ShouldBeOfType <SendGridProvider>();
        }
Example #11
0
        public void SendTestEmailReport()
        {
            // check...
            if (!(this.IsEmailReportingProperlyConfigured))
            {
                throw new InvalidOperationException("E-mail reporting is not properly configured.");
            }

            // get...
            ISmtpProvider provider = MailProviderFactory.GetSmtpProvider();

            provider.Settings = new SmtpConnectionSettings(this.EmailReportingHostName, this.EmailReportingUsername, this.EmailReportingPassword);

            // send...
            MailMessage message = new MailMessage();

            message.FromAsString = this.EmailReportingFrom;
            message.ToAsString   = this.EmailReportingTo;
            message.Subject      = string.Format("E-mail Error Reporting Test - {0} - {1}", Runtime.Current.Application.ProductCompany, Runtime.Current.Application.ProductName);
            message.Body         = "This is a test message from E-mail Error Reporting.";

            // send...
            provider.Send(message);
        }
Example #12
0
        public void GetMailProviderTest()
        {
            var mailProvider = MailProviderFactory.GetProvider();

            Assert.IsNotNull(mailProvider, "Mail provider is null.");
        }