Created
June 22, 2014 12:57
-
-
Save BalajiIyengar/df005e840423c8fba04c to your computer and use it in GitHub Desktop.
Sending Mails through c#.net
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
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