Created
April 18, 2017 14:28
-
-
Save chikien276/2cf4c2e6f2a3e5cff4d0cc5ef6faab3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Task SendEmailAsync(string email, string subject, string message) | |
{ | |
var msg = new MimeMessage(); | |
msg.From.Add(new MailboxAddress(EmailConfig.From, EmailConfig.FromEmail)); | |
msg.To.Add(new MailboxAddress("", email)); | |
msg.Subject = subject; | |
var bodyBuilder = new BodyBuilder(); | |
bodyBuilder.HtmlBody = message; | |
msg.Body = bodyBuilder.ToMessageBody(); | |
using (var client = new SmtpClient()) | |
{ | |
client.ServerCertificateValidationCallback = (s, c, ch, e) => true; | |
client.Connect("smtp.gmail.com", 587); | |
client.AuthenticationMechanisms.Remove("XOAUTH2"); | |
client.Authenticate(EmailConfig.Email, EmailConfig.Password); | |
client.Send(msg); | |
client.Disconnect(true); | |
} | |
return Task.FromResult(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment