.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Sending Email with ASP.NET

Posted By:Ashutosh Jha       Posted Date: February 27, 2014    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

Here i will explain how to send Plain and HTML emails in asp.net

Create a page named mail.aspx

and design it like the below-

<% @Page Language="C#" %>
<% @Import Namespace="System.Web.Mail" %>
string strTo = "ashutosh@gmail.com";
string strFrom = ashutosh@gmail.com
string strSubject = "Hello !";

SmtpMail.Send(strFrom, strTo, strSubject,
  "This is just for the demo purpose.");

Response.Write("Email sent successfully");

Execute it and you will get one popbox with the message of the email.

The complete email support resides in the System.Web.Mail namespace. In this namespace we find the class SmtpMail, whose static Send method can accept four parameters:

SmtpMail.Send(From, To, Subject, BodyText);

Now below code explain how to send HTML Emails- This is very simple. Lets create another page named htmlmail.aspx and write the below code-

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

msgMail.To = "ashutosh@gmail.Com";
msgMail.Cc = "ashutosh@gmail.Com";
msgMail.From = "ashutosh@gmail.Com";
msgMail.Subject = "Hello ! This is an HTML Email.";

msgMail.BodyFormat = MailFormat.Html;
string strBody = "<html><body><b>Hello Everyone</b>" +
   " <font color=\"red\">Email Sending as HTML</font></body></html>";
msgMail.Body = strBody;


Response.Write("Email sent successfully");




 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend