How to send Emails via ASP using SMTP authentication?

This topic includes the sample code to send email from ASP.Net using C# code :

Sample Code :

<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net.Mail" %>
 
<script language="C#" runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
       //create the mail message
        MailMessage mail = new MailMessage();
 
        //set the addresses
        mail.From = new MailAddress("yourname@yourdomain.com");
        mail.To.Add("recipient_email@domain.com");
        
        //set the content
        mail.Subject = "This is a test email from C# script";
        mail.Body = "This is a test email from C# script";
        //send the message
         SmtpClient smtp = new SmtpClient("smtp.yourdomain.com");
          
         NetworkCredential Credentials = new NetworkCredential("smtp@yourdomain.com", "password");
         smtp.Credentials = Credentials;
         smtp.Send(mail);
         lblMessage.Text = "Mail Sent";
    }
</script>
<html>
<body>
    <form runat="server">
        <asp:Label id="lblMessage" runat="server"></asp:Label>
    </form>
</body>

Note :-  You will require to make some changes in your script like SMTP server, email address & password etc.
  • 164 Users Found This Useful

Was this answer helpful?


Related Articles

How to use ASP Email?

ASPEmail 5.0 is an active server component for sending e-mail messages using an external SMTP...

Sample script for CDO email

CDO (Collaboration Data Objects) is an inbuilt ASP component used to send emails via ASP. It is...

MySQL ODBC driver on Windows 2008 / 2012 server

We have installed MySQL 5.1 ODBC driver on Windows 2008 / 2012 shared hosting server.

How to use ASPSMS?

Here is the ASP VB-Script example, intended to be used on an IIS (Internet Information Server)...

How to send email through CDONTS Email?

CDONTS stands for "Collaboration Data Objects for Windows NT Server" and as the name suggests it...