Share and download high quality stock photos

Network sites: Free Tutorials  |  Free Templates  |  CSS Gallery Showcase  |  Royalty Free Textures

How to programatically send an email through ASP.NET 2.0 and C#

Article by Andre Showairy - November 18, 2006

protected bool SendMessageAsEmail()
{
bool RetVal = true;
MailMessage objEmail = new MailMessage();
objEmail.To.Add("toemail@somewebsite.com");
objEmail.From = new MailAddress("fromemail@somewebsite.com");
objEmail.Subject = "Message from a visitor";
objEmail.Body = "this is the body of the message";
objEmail.Priority = MailPriority.High; // if you want to change the priority; else, remove this line


try
{
SmtpClient smtp = new SmtpClient("mailserver.com");
smtp.Port = 5544; // if port has a specific value; else, remove this line
smtp.EnableSsl = false;
smtp.Credentials = new NetworkCredential("emailAccountName", "emailAccountPassword");
smtp.Send(objEmail);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
RetVal = false;
}
return RetVal;
}

For any question, do not hesitate to contact me on:

Andre Showairy
writing@imagesti.com
http://www.imagesti.com
About the author
Computer Scientist since 1991.
In programming since 1991.
In C++ programming since 1993.
Long experience in VB, C#, VB.NET, ASP.NET, and ADO.NET.
Founder and owner of IT Images - http://www.imagesti.com


Back to articles