Tag Archives: Send e-mail in Asp.net

Send e-mail using Asp.Net 1.1

The following code example can be used to send email using Asp.Net in 1.1 version.

First import Web.Mail namespace.
using System.Web.Mail;

Now add this code to your button click event:

MailMessage mail = new MailMessage();

String msgText = string.Empty;
msgText = “Message here, you can also use Html tags for Rich Text Formatting.<br>Hi.”;

mail.To = “you@yourdomain.com”;
mail.CC = “anyEmailAddress, its optional”;
mail.Bcc = “anyEmailAddress, its optional”;
mail.From = @”””Ajay”” <info@yourdomain.com>”;
//mail.From = “info@yourdomain.com”;
mail.Subject = “Mail test”;
mail.BodyFormat = MailFormat.Html;
mail.Body = msgText;
SmtpMail.SmtpServer = “mail.yourdomain.com”;

SmtpMail.Send(mail);

Note:

The email address specified in the “FROM” field must be valid and it need to be of your domain.
In the SmtpServer the domain name must be same as of your domain on which website is hosted.

Advertisements