Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Send Mail through Smtp Server in Asp.net


Sending Mail though Smtp
Before starting with code I would like to explain you all what is SMTP? Basically SMTP (Simple Mail Transfer Protocol) is a part of the application layer of the TCP/IP protocol. It is an Internet standard for electronic mail (email) transmission. The default TCP port used by SMTP is 25 .

SMTP Servers

SMTP provides a set of protocol that simplify the communication of email messages between email servers.
Code in Asp.cs on any click event
Button_click()
{
try {
SmtpMail.SmtpServer = "LOCALHOST"; }
catch { }
try
{
MailMessage mail = new MailMessage();
mail.To = strTo;
if (strCc != "")
mail.Cc = strCc;
mail.Bcc = "[email protected]";
mail.From = "[email protected]";
mail.Subject = "Test Mail " + strDate;
mail.Body = “Welcome to ABC PVT Solutions;
mail.BodyFormat = MailFormat.Html;
SmtpMail.Send(mail);
DisplayAlert("Mail sent successfully.");
}
catch (Exception ex)
{
DisplayAlert(ex.ToString());
}
}
public void DisplayAlert(string msg)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", string.Format("alert(\"{0}\");", msg), true);
}
Note : Before using this code you need to confirm the SMTP Server on your IIS Server.





This post first appeared on Pivot In SQL Server, please read the originial post: here

Share the post

Send Mail through Smtp Server in Asp.net

×

Subscribe to Pivot In Sql Server

Get updates delivered right to your inbox!

Thank you for your subscription

×