public async Task SendEmailWithTemplateAsync(SendEmailWithTemplateModel model) { var randomGuid = Guid.NewGuid().ToString(); //var cleanUri = _options.Value.Protocol + model.Uri.Replace("api/", ""); var htmlFilePath = "./html-files/" + model.Template + ".html"; var builder = new BodyBuilder { HtmlBody = File.ReadAllText(htmlFilePath).Replace("^Fullname^", model.FullName) .Replace("^Link^", model.Link) .Replace("^RandomGuid^", randomGuid) }; var emailMessage = new MimeMessage { From = { new MailboxAddress(_options.Value.SenderEmail) }, To = { new MailboxAddress(_options.Value.Name, model.Recipient) }, Subject = model.Subject, Body = builder.ToMessageBody() }; using (var client = new SmtpClient()) { client.ServerCertificateValidationCallback = (s, c, h, e) => true; await client.ConnectAsync(_options.Value.Smtp, _options.Value.Port, false).ConfigureAwait(false); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(_options.Value.SmtpUsername, _options.Value.SmtpPassword); await client.SendAsync(emailMessage).ConfigureAwait(false); await client.DisconnectAsync(true).ConfigureAwait(false); } }
public async Task SendEmailWithTemplateAsync(SendEmailWithTemplateModel model) { await _emailDaemon.SendEmailWithTemplateAsync(model); }