Created
August 18, 2019 17:52
-
-
Save codehaks/1681d0b52996a1599e50a21f99e2c065 to your computer and use it in GitHub Desktop.
Send Email in ASP.NET Core 2.0+
This file contains 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 class EmailSender : IEmailSender | |
{ | |
public Task SendEmailAsync(string email, string subject, string message) | |
{ | |
SmtpClient client = new SmtpClient("mail.mysite.com") | |
{ | |
UseDefaultCredentials = false | |
}; | |
client.Credentials = new NetworkCredential("noreply@mysite.com", "password"); | |
MailMessage mailMessage = new MailMessage | |
{ | |
From = new MailAddress("noreply@mysite.com") | |
}; | |
mailMessage.IsBodyHtml = true; | |
mailMessage.Body = message; | |
mailMessage.Subject = subject; | |
mailMessage.To.Add(email); | |
client.Send(mailMessage); | |
return Task.CompletedTask; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment