Send E-mail in ASP.Net C# and VB.Net

Send email in ASP.Net

Send E-mail in ASP.Net 2.0 is easy task…

First Add Namespace System.Net.Mail to send email.

Send email using C#

<%@ Import Namespace=”System.Net.Mail” %>

protected void Page_Load(object sender, EventArgs e)
//create the email message
MailMessage email = new MailMessage();
//set the from addresses
email.From = new MailAddress(“”);

//set the to Address

//set the email subject and body , message
email.Subject = “Subject of Email – MeeraAcademyl”;
email.Body = “This is the Body of Email / Message of Email.”;

//send the message using smtpclient
SmtpClient smtp = new SmtpClient(“localhost”);
lblmsg.Text = “Send Mail Successfullyt”;

Now here is code of VB.Net

<%@ Import Namespace=”System.Net.Mail” %>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim strFrom = “”
Dim strTo = “”

Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo))
MailMsg.BodyEncoding = Encoding.Default
MailMsg.Subject = “Subject of Email”
MailMsg.Body = “This is a Test sample message”
MailMsg.Priority = MailPriority.High
MailMsg.IsBodyHtml = True
‘Smtpclient to send the mail message
Dim SmtpMail As New SmtpClient
SmtpMail.Host = “localhost”
lblmsg.Text = “Send Mail Successfullyt”;
End Sub

If you have any problem with this code, please write us………

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha *