send emails via ASP using SMTP authentication?

How to send emails via ASP SMTP authentication?

 

This includes the sample code to send emails 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 scripts like SMTP server, email address, and password, etc.

 

 

 

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Configure email account on Android mobile phone

You can follow these steps to configure your email account on your Andriod mobile phone. -...

Configuring the email account on your iPhone

Please follow these steps to configure your email account on your iPhone. - Please go to...

Add a POP3 account in your Gmail account

- Please login into your Gmail account and click on the "settings" button on the right side of...

Configure an email account in Mac Entourage

Please Go to "Entourage/Account Settings" After please click on the "New/Configure account...

Configure an email account in Mac Mail

- Please go to "Mail/Preferences" - Please go to "Accounts" -  -  Please click "+" to add a...

Powered by WHMCompleteSolution