Sending Email From ASP.NET (Version 2.0+)

Sending Email From ASP.NET (Version 2.0+)

ASP.NET is Microsoft’s revolutionary web application technology. ASP.NET has many features built in which other web language framworks don’t support, for example AJAX and drag-n-drop technologies.

In this article you will learn how to send emails from an ASP.NET (.aspx) page.

Note: This will only work with version 2.0+ of the framwork.

1) Import the mail namespace into the page.

2) Create the sub-routine that will send the email.

Sub SendEmail(ByVal Sender As Object, ByVal e As EventArgs)

End Sub

To send the mail on page load use the follow sub-routine.

Sub PageLoad(ByVal Sender As Object, ByVal e As EventArgs)

End Sub

Note: All sub-routines must be surrounded by the following tags.

Sub-routine here.

3) Declare the appropriate variables.

Dim msg As MailMessage = new MailMessage()
Dim smtp As New SmtpClient(“smtp.yourdomain.com”)

4) Start adding the appropriate details.

msg.From = new MailAddress(“[email protected]“, “From Person”)
msg.To.Add(new MailAddress(“
[email protected]“, “Recipient”))
msg.IsBodyHtml = “False”  ‘Set this to “True” if the message body will be HTML.
msg.Body = “Email Body”
msg.Subject = “The Subject”

5) Send the email.

smtp.Send(msg)

That’s how to send an email using ASP.NET 2.0 (+)!

Sharing

1 Comments

  1. The namespace won’t display in the post for some reason, but here it is:

    “System.Net.Mail”, you will need to search how to import it, since it won’t display.

Leave your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.