Sending Plain Text Email in ASP.NET 2.0


.NET Framework namespace System.Net.Mail contains many classes developers can use to send all types of emails in ASP.NET 2.0. In the following tutorial I will show you how you can send a simple plain text email in ASP.NET 2.0.

C#

using System.Net.Mail; 

string mailFrom = "waqas@ezzylearning.com";
string mailTo = "waqas@ezzylearning.com";
string subject = "ASP.NET Test Email";
string messageBody = "This email is send to you from ASP.NET";

// Create Mail Message Object
MailMessage message = new MailMessage(mailFrom, mailTo, subject, messageBody);

// Create SmtpClient class object to Send MailMessage
SmtpClient client = new SmtpClient();

// Here you specify your smtp host address such as smtp.myserver.com 
client.Host = "localhost";

client.Send(message);​

VB.NET

Dim mailFrom As String = "waqas@ezzylearning.com" 
Dim mailTo As String = "waqas@ezzylearning.com"
Dim subject As String = "ASP.NET Test Email" 
Dim messageBody As String = "This email is send to you from ASP.NET"

' Create Mail Message Object 
Dim message As New MailMessage(mailFrom, mailTo, subject, messageBody)

' Create SmtpClient class object to Send MailMessage 
Dim client As New SmtpClient()

' Here you specify your smtp host address such as smtp.myserver.com 
client.Host = "localhost"

client.Send(message)​

 

 

About author


User avatar

Waqas Anwar

Founder of EzzyLearning.com, Senior Consultant, Microsoft .NET and Web Technologies

Comments 1

Add Comment