Sending an Email using ASP.NET 2.0
Sending an Email is quite easy in ASP.NET 2.0. You can use the .NET Class SMTPMail to send the messages. The tricky part is when your server needs authentication. Many of the programmers stuck when it comes to pass UserName and Password of the SMTP Mail account to the server in order to send the email.
I am giving here the way to pass the username and password to send an email. Generally, it is required when you actually host your website on a shared third party web server.
System.Web.Mail.MailMessage ob= new MailMessage();
ob.To="info@YourDomaincom";
ob.From="mail@YourDomain.com";
ob.Subject="Contact From Our Website";
ob.Body= "Name :" + txtName.Text + "
" +"Email:" + txtEmail.Text ; ob.Priority=MailPriority.High;
SmtpMail.SmtpServer="mail.YourDomain.com";
ob.Fields.Add("https://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
ob.Fields.Add("https://schemas.microsoft.com/cdo/configuration/sendusername", "Email@YourDomain.com");
ob.Fields.Add("https://schemas.microsoft.com/cdo/configuration/sendpassword", "password");
try
{
SmtpMail.Send(ob);
lblMsg.Text="Message Sent";
}
catch (Exception ex)
{
Response.Write("Send failure: " + ex.Message);
}
I hope this is useful.
~Sandeep
Comments
- Anonymous
September 04, 2006
kj - Anonymous
September 10, 2006
Good Work Sir - Anonymous
September 11, 2006
these classes (System.Web.Mail.*) are deprecated in ASP.NET 2.0 ... - Anonymous
September 22, 2006
Thanks for the nice explaination
i would be pleased if you can answer my Q
i hava a form which contains a data on it
i want after clicking the update button or insert button the ASP.NET sends an automatic email to the user to welcome him in the database.
Thanks - Anonymous
March 13, 2008
is there any chance in getting this code invb.net please for the comment above