1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Discuss in my forum

How to Send a Simple Email with ASP.NET

By

Pensive senior man with laptop
Jose Luis Pelaez/The Image Bank/Getty Images
Sending a simple email from an ASP.NET is just as simple as (and looks very similar to) doing the same in PHP.

Send a Simple Email with ASP.NET

First, we need to import the System.Web.Mail namespace:

<%@ Import Namespace="System.Web.Mail" %>

Sending the message is a matter of calling SmtpMail.Send() with the following arguments: sender, recipient, subject and body. For example, we'd send an email in C# like this:

string from = "sender@example.com";
 string to = "recipient@example.com";
 string subject = "Hi!";
 string body = "How are you?";
 SmtpMail.SmtpServer = "mail.example.com";
 SmtpMail.Send(from, to, subject, body);

SmtpMail.SmtpServer lets you specify the mail server used to deliver your message.

©2014 About.com. All rights reserved.