Send Email c#

September 23, 2010

Here’s how to send some email in c#

using System.Net.Mail;
using System.Net.Mime;
using System.Net;

///place in a sub-routine or button
try
{
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient("smtp.example.com");
MailMessage message = new MailMessage("user@example.com", "user@example.com"); // , 
message.Body = "test e-mail"
message.Subject = "Test Subject from C#"
client.Port = System.Convert.ToInt32("25");
client.Send(message);
MessageBox.Show("Email Sent Successfully");
}
catch (Exception ex)
{
    MessageBox.Show("Cannot send message: " + ex.Message);
}