1and1 Help Centre Categories

print article

Send an E-Mail Using ASP.NET

Find out how to send an E-mail through ASP.NET using the System.Net.Mail namespace.

Use the script below as an example on how to seed an E-mail using the System.Net.Mail namespace now that System.Web.Mail is not longer up to date.

<%@ 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.co.uk");
//set the RECIPIENTS
//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 auth.smtp.1and1.co.uk)
SmtpClient smtp = new SmtpClient("auth.smtp.1and1.co.uk");
//Enter your full e-mail address and password
smtp.Credentials = new NetworkCredential("address@youdomain.co.uk", "yourEmailPassword");
//send the message

For additional information, you may want to reference: