1. Home
  2. Computing & Technology
  3. Email

How to Send a Simple Email with ASP.NET

By , About.com Guide

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.

Explore Email
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Email
  4. How Email Works
  5. Email Programming Tips
  6. How to Send a Simple Email with ASP.NET - About Email>

©2009 About.com, a part of The New York Times Company.

All rights reserved.