Home » Categories » Multiple Categories

Sample Code to Send email using ASP.NET1.1

Our mail server is configured with SMTP authentication and all your code need to use SMTP Authentication before you can send email. If your code does not use SMTP authentication, the email will not be sent.

private void Page_Load(object sender, System.EventArgs e)
     MailMessage mail = new MailMessage();
     mail.To = "me@mycompany.com";
     mail.From = "you@yourcompany.com";
     mail.Subject = "this is a test email.";
     mail.Body = "Some text goes here";
     mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
     mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
     mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here

     SmtpMail.SmtpServer = "localhost"; //your real server goes here
     SmtpMail.Send( mail );

Please note that you need to use localhost as the SMTP detail as there is no remote connection made between your site and our mail server.

Attachments Attachments
There are no attachments for this article.
Related Articles RSS Feed
My site is showing 500 Internal Server error message. What is wrong here?
Viewed 2130 times since Thu, May 3, 2012
Do you allow custom COM components?
Viewed 1656 times since Tue, May 1, 2012
How do I redirect a subdomain to a subdirectory?
Viewed 2243 times since Tue, May 1, 2012
How to Solve an Error Message "Validation of viewstate MAC failed"
Viewed 6565 times since Tue, Apr 2, 2013
My website session times out earlier than expected. Why?
Viewed 2883 times since Tue, May 1, 2012
Domain Name Server (DNS) Amplification Attack
Viewed 1926 times since Wed, Oct 15, 2014
How do I query MySQL database in ASP.NET?
Viewed 4046 times since Tue, May 1, 2012
I receive this error message: "Directory Listing Denied. This Virtual Directory does not allow contents to be listed."
Viewed 4626 times since Mon, Apr 30, 2012