How to send email via system.web.mail class: ASP.Net

One can send email via simple System.Web.Mail class of ASP.Net. Below mentioned is sample code for the same:

<% @Page Language=”C#” %>
<% @Import Namespace=”System.Web.Mail” %>
<%
MailMessage msgMail = new MailMessage();

// Receiver’s email address … 
msgMail.To = “Recipient Email Address”;

// Sender’s email address … 
msgMail.From = “Sender’s email address”;

// Subject line of email … 
msgMail.Subject = “Subject of an email”;

// Body format – HTML or TEXT … 
msgMail.BodyFormat = MailFormat.Text;

// Content of your email … 
msgMail.Body = “Body contents”;

// If you want to add attachments, use this line … 
msgMail.Attachments.Add(new MailAttachment(“c:\shane.xls”));

// Following 3 lines are used for SMTP Authentication … 
msgMail.Fields.Add(
“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”“1”); 
msgMail.Fields.Add(
“http://schemas.microsoft.com/cdo/configuration/sendusername”YOUR EMAIL ADDRESS); 
msgMail.Fields.Add(
“http://schemas.microsoft.com/cdo/configuration/sendpassword”YOUR EMAIL ACCOUNT PASSWORD);
SmtpMail.Send(msgMail);

Thanks,

Rahul Vaghasia

Rahul Vaghasia

Rahul is CEO at AccuWebHosting.com. He shares his web hosting insights at AccuWebHosting blog. He mostly writes on the latest web hosting trends, WordPress, storage technologies, Windows and Linux hosting platforms.
Rahul Vaghasia
(Visited 84 times, 1 visits today)

Leave a Reply

AlphaOmega Captcha Classica  –  Enter Security Code
captcha      
 

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sign up for a News Letter Click here to sign up