Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SMTP Send E-Mail in C#
// This will read the username, password, and mail server information from the web.config file. Very easy way to send E-Mail in .NET.
//
// <mailSettings>
// <smtp from="firstname lastname&lt;youremail@youraddress.com&gt;">
// <network host="smtp.mailserver.com" port="25" userName="myusername@smtp.mailserver.com" password="mypassword" enableSsl="false" defaultCredentials="false" />
// </smtp>
// </mailSettings>
using System.Net.Mail;
class EMailExample
{
public void SendMail()
{
MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress("mail@example.com"));
mail.Subject = "E-Mail Subject";
mail.Body = "This is the body of my E-Mail";
using(SmtpClient smtp = new SmtpClient())
{
smtp.Send(mail);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.