Send email with smtp authentication using ASP.NET 3.5

 Rate It (0)

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");
        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.

Revision number 1, Tuesday, November 03, 2009 7:15:24 PM by arjit.malviya
This is not the most up to date version of this article. The most recent version can be found here.

Comments

Hi Thanks. MaxIdleTime is used for mass email.

Great

Shortcuts

Table of Contents

Top Wiki Contributors

(last 30 days)

  1. mbanavige (7)
  2. yrb.yogi (5)
  3. srinivaskotra (3)
  4. XIII (2)
  5. rdmartin33 (2)
  6. Babunareshnarra (2)
  7. Dungimon (1)
  8. ali62b (1)
Microsoft Communities