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(“meeraacademy@hotmail.com”);

//set the to Address
email.To.Add(“meeraacademy@hotmail.com”);

//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”);
smtp.Send(mail);
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 = “meeraacademy@hotmail.com”
Dim strTo = “meeraacademy@hotmail.com”

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”
SmtpMail.Send(MailMsg)
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 *

1 + 6 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">