public async Task SendMailWithOptions_Test() { var options = new PickupFolderMailerServiceOptions { BodyHtmlFormat = "<html><body>{0}<hr/>This is footer</body></html>", BodyTextFormat = "{0}\r\n--\r\nThis is footer", SubjectFormat = "[test] {0}", DefaultFrom = new MailAddressDto("*****@*****.**", "Example From"), DefaultSender = new MailAddressDto("*****@*****.**", "Example Sender"), PickupFolderName = CreateTempFolder("options") }; var mx = new PickupFolderMailerService(options); var msg = new MailMessageDto { Subject = "ОluЭouшk¤ k∙Є ·pьl ясbelskщ єdy - subject", BodyText = "ОluЭouшk¤ k∙Є ·pьl ясbelskщ єdy - text.", BodyHtml = "<p>ОluЭouшk¤ k∙Є ·pьl ясbelskщ єdy <b>v HTML</b>.</p>" }; msg.To.Add(new MailAddressDto("*****@*****.**", "Example Recipient")); using (var ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("Test attachment file"))) { msg.Attachments.Add(new AttachmentDto { Name = "attachment.txt", MimeType = "text/plain", Stream = ms }); await mx.SendMessageAsync(msg); } Assert.True(EmlFileExists(mx.PickupFolderName)); }
public static IServiceCollection AddPickupFolderMailerService(this IServiceCollection services, string pickupFolderName) { if (pickupFolderName == null) { throw new ArgumentNullException(nameof(pickupFolderName)); } if (string.IsNullOrWhiteSpace(pickupFolderName)) { throw new ArgumentException("Value cannot be empty or whitespace only string.", nameof(pickupFolderName)); } var options = new PickupFolderMailerServiceOptions { PickupFolderName = pickupFolderName }; services.AddSingleton <IMailerService>(new PickupFolderMailerService(options)); return(services); }
public static IServiceCollection AddPickupFolderMailerService(this IServiceCollection services, PickupFolderMailerServiceOptions options) { services.AddSingleton <IMailerService>(new PickupFolderMailerService(options)); return(services); }