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); }
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); }
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); }
public SmtpService(IOptions <SmtpServiceOptions> options) { _options = options.Value ?? throw new ArgumentNullException(nameof(options)); }