Created
June 7, 2013 15:24
-
-
Save mbalex99/5730080 to your computer and use it in GitHub Desktop.
C# Send Email
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 void SendEmail(string fromEmailAddress, string fromName, string fromPassword, string host, int port, | |
string toEmailAddress, string toName, string subject, string body, bool isHtmlEmail) | |
{ | |
var fromAddress = new MailAddress(fromEmailAddress, fromName); | |
var toAddress = new MailAddress(toEmailAddress, toName); | |
var smtp = new SmtpClient() | |
{ | |
Host = host, | |
Port = port, | |
EnableSsl = true, | |
DeliveryMethod = SmtpDeliveryMethod.Network, | |
UseDefaultCredentials = false, | |
Credentials = new NetworkCredential(fromEmailAddress, fromPassword) | |
}; | |
using (var message = new MailMessage(fromAddress, toAddress) | |
{ | |
Subject = subject, | |
Body = body, | |
IsBodyHtml = isHtmlEmail | |
}) | |
{ | |
smtp.Send(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment