Sending Plain Text Email in ASP.NET

You are currently viewing Sending Plain Text Email in ASP.NET

.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 emails in ASP.NET 2.0.

C#

using System.Net.Mail; 

string mailFrom = "[email protected]";
string mailTo = "[email protected]";
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 = "[email protected]" 
Dim mailTo As String = "[email protected]"
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)
READ ALSO:  Understanding ASP.NET ObjectDataSource Control

This Post Has One Comment

  1. Naghman Hameed

    This website is observed to be an excellent website for e-learning. Some complicated programming modules have been explained very appropriately.
    I pay tribute to Mr. Waqas for creating such a knowledgeable website. God bless you.

Leave a Reply