Exemple #1
0
        public void CreateFromMessageWithAttachment_ShouldSendToTemplateFactory_WithCustomTemplate(bool alwaysTemplateSetting)
        {
            //Arrange
            var options = new SmtpServiceOptions
            {
                AlwaysTemplateEmails = alwaysTemplateSetting
            };
            var factory = new MimeMessageFactory(new OptionsWrapper <SmtpServiceOptions>(options), _loggerMock.Object,
                                                 _hostingEnvironment.Object, _emailTemplateFactoryMock.Object);
            var from              = "*****@*****.**";
            var to                = "*****@*****.**";
            var attachment        = Encoding.ASCII.GetBytes("Testing");
            var fileName          = "file.txt";
            var subject           = "Subject";
            var bodyHtml          = "<p>Test</p>";
            var requestedTemplate = "testing";
            var updatedHtml       = "<h1>Templated</h1><p>Test</p>";

            _emailTemplateFactoryMock
            .Setup(e => e.BuildEmailContent(subject, bodyHtml, "", requestedTemplate))
            .Returns(updatedHtml)
            .Verifiable();

            //Act
            var result = factory.CreateFromMessageWithAttachment(from, to, null, subject, attachment, fileName, bodyHtml, requestedTemplate);

            //Assert
            _emailTemplateFactoryMock.Verify();
            Assert.Equal(updatedHtml, result.HtmlBody);
        }
Exemple #2
0
        public void CreateFromMessage_ShouldSendToTemplateFactory_WhenAlwaysUseTemplatedEmail()
        {
            //Arrange
            var options = new SmtpServiceOptions
            {
                AlwaysTemplateEmails = true
            };
            var factory = new MimeMessageFactory(new OptionsWrapper <SmtpServiceOptions>(options), _loggerMock.Object,
                                                 _hostingEnvironment.Object, _emailTemplateFactoryMock.Object);
            var from        = "*****@*****.**";
            var to          = "*****@*****.**";
            var subject     = "Subject";
            var bodyHtml    = "<p>Test</p>";
            var updatedHtml = "<h1>Templated</h1><p>Test</p>";

            _emailTemplateFactoryMock
            .Setup(e => e.BuildEmailContent(subject, bodyHtml, "", ""))
            .Returns(updatedHtml)
            .Verifiable();

            //Act
            var result = factory.CreateFromMessage(from, to, null, subject, bodyHtml);

            //Assert
            _emailTemplateFactoryMock.Verify();
            Assert.Equal(updatedHtml, result.HtmlBody);
        }
Exemple #3
0
        public void CreateFromMessageWithAttachment_ShouldModifyUrl_WhenSuffixEnabledAndNotProduction()
        {
            //Arrange
            var options = new SmtpServiceOptions()
            {
                AddEnvironmentSuffix = true,
                AlwaysTemplateEmails = false
            };
            var factory = new MimeMessageFactory(new OptionsWrapper <SmtpServiceOptions>(options), _loggerMock.Object, _hostingEnvironment.Object, _emailTemplateFactoryMock.Object);

            _hostingEnvironment.Setup(e => e.EnvironmentName).Returns("Development");
            var from            = "*****@*****.**";
            var to              = "*****@*****.**";
            var fileContent     = Encoding.ASCII.GetBytes("Testing");
            var fileName        = "test.txt";
            var subject         = "Subject";
            var bodyHtml        = "<p>Test</p>";
            var expectedSubject = "Subject (Development)";

            //Act
            var result = factory.CreateFromMessageWithAttachment(from, to, null, subject, fileContent, fileName, bodyHtml);

            //Assert
            Assert.Equal(expectedSubject, result.Subject);
        }
 public async Task SendByMailAsync(string email, SmtpServiceOptions options = null)
 {
     await _smtpService.SendAsync(email, _mailTemplate.Subject, _mailTemplate.Message, options);
 }
 public void SendByMail(string email, SmtpServiceOptions options = null)
 {
     _smtpService.Send(email, _mailTemplate.Subject, _mailTemplate.Message, options);
 }
Exemple #6
0
 public SmtpService(IOptions <SmtpServiceOptions> options)
 {
     _options = options.Value ?? throw new ArgumentNullException(nameof(options));
 }