Send email with smtp authentication using ASP.NET

Article Details
URL: http://www.mochasupport.com/kayako/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=811
Article ID: 811
Created On: 16 Sep 2017 12:41 AM

Answer

Send email with smtp authentication using ASP.NET

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

       //create the mail message

        MailMessage mail = new MailMessage();

        //set the addresses
        mail.From = new MailAddress("[email protected]"); //IMPORTANT: This must be same as your smtp authentication address.
        mail.To.Add("[email protected]");

        //set the content
        mail.Subject = "This is an email";
        mail.Body = "This is from system.net.mail using C sharp with smtp authentication.";
        //send the message
         SmtpClient smtp = new SmtpClient("mail.yourdomain.com");

        //IMPORANT:  Your smtp login email MUST be same as your FROM address.
         NetworkCredential Credentials = new NetworkCredential("[email protected]", "password");
         smtp.Credentials = Credentials;
         smtp.Send(mail);
         lblMessage.Text = "Mail Sent";


 

NOTE: Please note that you cannot use System.Net.Mail.SmtpClient to send an e-mail message with Implicit SSL. For more details please clich HERE.