View Single Post
  #1 (permalink)  
Old 21-05-2007, 12:15
flesso's Avatar
flesso flesso is offline
Premium Member
 
Join Date: Mar 2007
Location: 127.0.0.1
Posts: 1,359
Default Send Email From ASP.NET

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.

PHP Code:

<%@ Import Namespace="System.Net.Mail" %> 
2) Create the sub-routine that will send the email.

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

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

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

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

PHP Code:

<script language="VB" runat="server">

Sub-routine here.

</script> 
3) Declare the appropriate variables.

Code:
Dim msg As MailMessage = new MailMessage()
Dim smtp As New SmtpClient("smtp.yourdomain.com")
4) Start adding the appropriate details.

Code:
msg.From = new MailAddress("from@yourdomain.com", "From Person")
msg.To.Add(new MailAddress("recipient@domain.com", "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.

Code:
smtp.Send(msg)
That's how to send an email using ASP.NET 2.0 (+)!
__________________
Regards,
Josh Hold


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Over 1000 Computer Related Articles to Sink Your Teeth Into!



To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Gig Listings for London


Super Moderator
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


I'm only a forum gremlin (moderator), and do not work for eUKhost in any way. Opinions expressed by me are mine only, and do not reflect those of either eUKhost or any company that may be listed above.

I don't bite, honest.

Last edited by flesso; 21-05-2007 at 15:08.
Reply With Quote