public async Task SendEmail(Form from) { string html = await _razorLightEngine.CompileRenderAsync <object>(Template, from); User user = await repository.GetUserById(from.SenderId); SmtpConfiguration configuration = await service.GetConfiguration(); Email.DefaultSender = new SmtpSender(new SmtpClient { Host = configuration.Host, Port = int.Parse(configuration.Port), Credentials = new NetworkCredential(configuration.Username, configuration.Password) }); SendResponse sendResponse = await Email .From(configuration.From) .To(configuration.To) .Subject($"New Message from: {user.Username}") .Body(html, true) .SendAsync(); if (!sendResponse.Successful) { //Todo log } }
public Task <SmtpConfiguration> Handle(GetSmtpConfigurationQuery request, CancellationToken cancellationToken) { return(smtpSerive.GetConfiguration()); }