Select Category
Sitemap Help Contact
print article

Send an E-mail Using ASP.NET

Follow the steps below to send an e-mail through ASP.NET using the System.Net.Mail namespace.

Use the script below as an example for how to sned an e-mail using the System.Net.Mail namespace now that System.Web.Mail has been deprecated.

<%@ Import Namespace="System.Net"%>
<%@ Import Namespace="System.Net.Mail"%>
<%@ Page Language="C#" %>

<%
//create the mail message
MailMessage mail = new MailMessage();
//set the FROM address
mail.From = new MailAddress("address@yourdomain.com");
//set the RECIPIENTS
mail.To.Add("recipient@theirdomain.com");
//enter a SUBJECT
mail.Subject = "Set the subject of the mail here.";
//Enter the message BODY
mail.Body = "Enter text for the e-mail here.";
//set the mail server (default should be smtp.1and1.com)
SmtpClient smtp = new SmtpClient("smtp.1and1.com");
//Enter your full e-mail address and password
smtp.Credentials = new NetworkCredential("address@youdomain.com", "yourEmailPassword");
//send the message
smtp.Send(mail);

%>

For additional information, you may want to reference: