How do I send an email from my ASP.NET page?
Include the System.Web.Mail.MailMessage and the System.Web.Mail.SmtpMail classes to send email from ASPX pages.Below is a sample of sending email using said classes in C#.
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Mail" %>
<html>
<head>
<title>Mail Test</title>
</head>
<script language="C#" runat="server">
private void Page_Load(Object sender, EventArgs e)
{
try
{
MailMessage mailObj = new MailMessage();
mailObj.From = "xyz@programmersheaven.com";
'mail from address
mailObj.To = "abc@hotmail.com";
'mail to address
mailObj.Subject = "New Article Suggestion";
'mail subject
mailObj.Body = "I am sending a link to this article which is really very interesting";
'mail body
mailObj.BodyFormat = MailFormat.Text;
SmtpMail.SmtpServer = "mail.programmersheaven.com";
'specify mail server name depending on your mail server
SmtpMail.Send(mailObj);
Response.Write("Mail sent successfully");
}
catch (Exception x)
{
Response.Write("Your message was not sent: " + x.Message);
}
}
</script>
<body>
<form id="mail_test" method="post" runat="server">
</form>
</body>
</HTML>
Tip
In order to send email through your mail server, you should set the static SmtpServer property of the SmtpMail class to mail-fwd.
Written by Sandeep Mogulla, Webmaster at www.startvbdotnet.com
Index
Sponsored links
3 Months Free - ASP.NET Web Hosting
3 Months Free & No Setup Fees on ASP.NET 3.5/2.0 Hosting on Windows 2008/2003 Servers ? Click Here!
3 Months Free & No Setup Fees on ASP.NET 3.5/2.0 Hosting on Windows 2008/2003 Servers ? Click Here!
SFTP components for .NET
Add complete SSH and SFTP support to your .NET framework application
Add complete SSH and SFTP support to your .NET framework application
PureCM Software Configuration Management
Version control and integrated issue tracking - powerful and easy to use. Get your FREE trial now!
Version control and integrated issue tracking - powerful and easy to use. Get your FREE trial now!
Six Sigma Certification
100% Online-Six Sigma Certificate from Villanova - Find Out More Now.
100% Online-Six Sigma Certificate from Villanova - Find Out More Now.
Web based bug tracking - AdminiTrack.com
AdminiTrack offers an effective web-based bug tracking system designed for professional software development teams.
AdminiTrack offers an effective web-based bug tracking system designed for professional software development teams.
