Click here to Skip to main content
15,880,608 members
Articles / Web Development / ASP.NET
Article

Send email with smtp authentication using ASP.NET 3.5

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
11 Oct 2013CPOL 26.1K   3  
Following Codes demonstrates how to send an email with SMTP Authentication using ASP.NET 3.5using System.Net.Mail        MailMessage msgMail =

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Following Codes demonstrates how to send an email with SMTP Authentication using ASP.NET 3.5

using System.Net.Mail

        MailMessage msgMail = new MailMessage();

        MailMessage myMessage = new MailMessage();
        myMessage.From = new MailAddress("sender's email","sender`s name and surname");
        myMessage.To.Add("recipient's email");
        myMessage.Subject = "Subject";
        myMessage.IsBodyHtml = true;

        myMessage.Body = "Message Body";


        SmtpClient mySmtpClient = new SmtpClient();
        System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("email", "password");
        mySmtpClient.Host = "your smtp host address";
        mySmtpClient.UseDefaultCredentials = false;
        mySmtpClient.Credentials = myCredential;
        mySmtpClient.ServicePoint.MaxIdleTime = 1;

        mySmtpClient.Send(myMessage);
        myMessage.Dispose();


Note : You can avoid mySmtpClient.ServicePoint.MaxIdleTime, as it is to force the SmtpClient to send mail immediately with the .Send method.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

755 members

Comments and Discussions

 
-- There are no messages in this forum --