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("[email protected]");
        mail.To.Add("[email protected]");
        
        //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("[email protected]", "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.

Looking to send emails using ASP.NET (VB)? Click on Send Mail > Using ASP.NET (VB) for more details. 

Related Articles

How to disable Deprecated Function Notices in PHP?

PHP has deprecated some functions in latest version. If the same functions are still on your...

FormMail script for Windows 2008 / 2012 customers

We don't offer Windows 2008 and 2012 Shared Hosting but we offer Windows Server 2016 with Plesk...

How to send emails using ASP.Net (VB)?

This topic includes the sample code to send email from ASP.Net(VB) code :Sample Code : <%@...

ASPJpeg support on Windows 2008 / 2012 servers

We don't offer Windows Server 2008 and 2012 with shared hosting services anymore. We have...

Microsoft Access and ASP connection script for Windwos 2008 / 2012 shared hosting

We don't offer Windows 2008 or Windows 2012 Shared Hosting Service anymore but we now offer...

  • 164 Users Found This Useful

Was this answer helpful?