Skip to content

Instantly share code, notes, and snippets.

@mbalex99
Created June 7, 2013 15:24
Show Gist options
  • Save mbalex99/5730080 to your computer and use it in GitHub Desktop.
Save mbalex99/5730080 to your computer and use it in GitHub Desktop.
C# Send Email
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