Logo
Color-Of-Code
  Home   All tags   Terms and Conditions

SMTP

December 27, 2018

C# SMTP

Assembly (reference)

System

Using directive

using System.Net.Mail;

Code: send an Email

For details: http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx

SmtpClient client = new SmtpClient("SMTP mail server name or IP goes here");

// (do not use ';', this was used in previous API )
String to          = "Email recipients go here [',' separated]";
String from        = "Sender Email goes here"; 

MailMessage message = new MailMessage(from, to);
message.Subject     = "Email title goes here";
message.Body        = "Body text goes here";
client.Credentials  = CredentialCache.DefaultNetworkCredentials;

client.Send(message);