Knowing how to send email from a web application is very important. It is has many applications, some being email confirmation, forgot password, message to admin, promotions, any other generic messages and the list goes on and on.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
MailMessage message = new MailMessage();  
SmtpClient client = new SmtpClient();

//Email fields
message.From = new MailAddress("[email protected]");
message.To.Add("[email protected]");
message.Subject = "Welcome";
message.Body = "The Body";

//To add any attachments to the email
message.Attachments.Add(new Attachment());

//Your email Credentials 
client.Credentials = new NetworkCredential("EmailUserName", "EmailPassword");

//These are the different email providers, use the appropriate client for your email
//Gmail
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;

//Yahoo
client.Host = "smtp.mail.yahoo.com";
client.Port = 587;
client.EnableSsl = true;

//Hotmail, outlook, live 
client.Host = "smtp.live.com";
client.Port = 587;
client.EnableSsl = true;

//To send email
client.Send(message);

The code snippet is pretty self explanatory. For an actual working winform application which sends email check out this project on github.