Code to Send Email in ASP.Net



This code is use to send email via ASP.Net Page.
Generally it should be required to send the information like Login status,
update status or any updations to the user. This purpose you can use this code.

Below is the code to send mail in

Dim mail As New MailMessage()

mail.[To] = "Receivers ID"
mail.From = "Sender ID"

mail.Subject = "Test Mail"
mail.BodyFormat = MailFormat.Html
mail.Body = (("<html><body>Dear ") + "Hi" & " </b> <br><br>") + " <br><br> <font color=orange>Click on the below link to be a part of DotNetSpider.</font><br><a href=>Download Order</a><br><br><b> Do not Reply to this e-mail.</b><br><br>Thanks <br></body></html>"


Catch ex As Exception
End Try

Nilesh Jadhav


Author: ABitSmart30 Nov 2009 Member Level: Gold   Points : 0

Please format your resource.

Author: mithun29 Dec 2009 Member Level: Bronze   Points : 2

MailMessage mail = new MailMessage();
mail.From = FromAddress;
mail.To = ToAddress;
mail.Cc = CcAddress;

mail.Subject = Subject.ToString().Trim();

StringBuilder sbMailContent = new StringBuilder();
sbMailContent.Append(MailBody + "

mail.Body = "" + "" + sbMailContent + "" + "";

mail.BodyFormat = MailFormat.Html;

//SmtpMail.SmtpServer = server name

mail.Fields.Add("", 25);
mail.Fields.Add("", "1"); //basic authentication
mail.Fields.Add("", server username);
mail.Fields.Add("", server password]);
mail.Fields.Add("", 120);


Author: Er. Ram Singh06 Sep 2010 Member Level: Gold   Points : 2

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Net.Mail;public partial class Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) {//Calling the function SendMail Response.Write( SendMail("","","","Test Mail","Test Mail Body")); } public string SendMail(string toList, string from, string ccList, string subject, string body) { MailMessage message = new MailMessage(); SmtpClient smtpClient = new SmtpClient(); string msg = string.Empty; try { MailAddress fromAddress = new MailAddress(from); message.From = fromAddress; message.To.Add(toList); if (ccList != null && ccList != string.Empty) message.CC.Add(ccList); message.Subject = subject; message.IsBodyHtml = true; message.Body = body; smtpClient.Host = ""; smtpClient.Port = 25; smtpClient.UseDefaultCredentials = true; smtpClient.Credentials = new System.Net.NetworkCredential("", "password"); smtpClient.Send(message); msg = "Successful"; } catch (Exception ex) { msg = ex.Message; } return msg; }}

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: