Skip to content

Instantly share code, notes, and snippets.

@BalajiIyengar
Created June 22, 2014 12:57
Show Gist options
  • Save BalajiIyengar/df005e840423c8fba04c to your computer and use it in GitHub Desktop.
Save BalajiIyengar/df005e840423c8fba04c to your computer and use it in GitHub Desktop.
Sending Mails through c#.net
var fromAddress = new MailAddress("[email protected]", "Balaji Iyengar");
var toAddress = new MailAddress("[email protected]", "c# balaji");
const string fromPassword = "xyz";
const string subject = "My First c# mail";
const string body = "Yay,it worked.";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment