public async Task SendEmail_WithDisplayName() { var pickupDirectoryPath = Path.Combine(Directory.GetCurrentDirectory(), "Email"); if (Directory.Exists(pickupDirectoryPath)) { var directory = new DirectoryInfo(pickupDirectoryPath); directory.GetFiles().ToList().ForEach(f => f.Delete()); } Directory.CreateDirectory(pickupDirectoryPath); var options = new Mock <IOptions <SmtpSettings> >(); options.Setup(o => o.Value).Returns(new SmtpSettings { DefaultSender = "Your Name <*****@*****.**>", DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory, PickupDirectoryLocation = pickupDirectoryPath }); var logger = new Mock <ILogger <SmtpService> >(); var localizer = new Mock <IStringLocalizer <SmtpService> >(); var smtp = new SmtpService(options.Object, logger.Object, localizer.Object); var message = new MailMessage { To = "*****@*****.**", Subject = "Test", Body = "Test Message" }; var result = await smtp.SendAsync(message); Assert.True(result.Succeeded); }
private async Task <string> SendEmailAsync(string defaultSender, MailMessage message) { var pickupDirectoryPath = Path.Combine(Directory.GetCurrentDirectory(), "Email"); if (Directory.Exists(pickupDirectoryPath)) { var directory = new DirectoryInfo(pickupDirectoryPath); directory.GetFiles().ToList().ForEach(f => f.Delete()); } Directory.CreateDirectory(pickupDirectoryPath); var options = new Mock <IOptions <SmtpSettings> >(); options.Setup(o => o.Value).Returns(new SmtpSettings { DefaultSender = defaultSender, DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory, PickupDirectoryLocation = pickupDirectoryPath }); var logger = new Mock <ILogger <SmtpService> >(); var localizer = new Mock <IStringLocalizer <SmtpService> >(); var smtp = new SmtpService(options.Object, logger.Object, localizer.Object); var result = await smtp.SendAsync(message); Assert.True(result.Succeeded); var file = new DirectoryInfo(pickupDirectoryPath).GetFiles().FirstOrDefault(); Assert.NotNull(file); var content = File.ReadAllText(file.FullName); return(content); }
public async Task SendEmail_UsesReplyTo() { var pickupDirectoryPath = Path.Combine(Directory.GetCurrentDirectory(), "Email"); if (Directory.Exists(pickupDirectoryPath)) { var directory = new DirectoryInfo(pickupDirectoryPath); directory.GetFiles().ToList().ForEach(f => f.Delete()); } Directory.CreateDirectory(pickupDirectoryPath); var options = new Mock <IOptions <SmtpSettings> >(); options.Setup(o => o.Value).Returns(new SmtpSettings { DefaultSender = "Your Name <*****@*****.**>", DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory, PickupDirectoryLocation = pickupDirectoryPath }); var logger = new Mock <ILogger <SmtpService> >(); var localizer = new Mock <IStringLocalizer <SmtpService> >(); var smtp = new SmtpService(options.Object, logger.Object, localizer.Object); var message = new MailMessage { To = "*****@*****.**", Subject = "Test", Body = "Test Message", From = "*****@*****.**", ReplyTo = "*****@*****.**", }; var result = await smtp.SendAsync(message); Assert.True(result.Succeeded); var file = new DirectoryInfo(pickupDirectoryPath).GetFiles().FirstOrDefault(); Assert.NotNull(file); var content = File.ReadAllText(file.FullName); Assert.Contains("From: [email protected]", content); }