UK WEB HOSTING FORUM FOR DISCUSSION ON WEB HOSTING SERVICE AND SUPPORT
LINUX HOSTING WINDOWS HOSTING PACKAGES SHOPPING CART OSCOMMERCE ZEN CART AGORA
ECOMMERCE HOSTING ASP MSSQL FRONTPAGE HOSTING PHP MYSQL HOSTING DISCUSSION FORUM
CPANEL RESELLER HOSTING DEDICATED SERVER VPS HOSTING PLESK VIRTUOZZO
Quick Search
Your forum announcement here!

  UK Web Hosting | Dedicated Server Windows and Linux VPS Forum > Technical Support > Windows Reseller Hosting

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 21-05-2007, 12:15
flesso's Avatar
Premium Member
 
Join Date: Mar 2007
Location: 127.0.0.1
Posts: 1,194
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

eUKhost Blog: Over 1000 Computer Related Articles to Sink Your Teeth Into!

Super Moderator

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.

Last edited by flesso : 21-05-2007 at 15:08.
Reply With Quote
  #2 (permalink)  
Old 21-05-2007, 12:38
steppen's Avatar
Member
 
Join Date: May 2007
Location: Norway
Posts: 36
Send a message via MSN to steppen Send a message via Skype™ to steppen
Default

Guess you will notice, but the frame under "Note: All sub-routines must be surrounded by the following tags." is empty.
__________________
Stein
Reply With Quote
  #3 (permalink)  
Old 21-05-2007, 12:41
DPS Computing's Avatar
Premium Member
 
Join Date: Apr 2007
Location: Manchester, United Kingdom
Posts: 4,458
Send a message via ICQ to DPS Computing Send a message via AIM to DPS Computing Send a message via MSN to DPS Computing Send a message via Yahoo to DPS Computing Send a message via Skype™ to DPS Computing
Default

On that note, the code section under "1) Import the mail namespace into the page." is also blank.
__________________
David Smith
DPS Computing
http://www.dpscomputing.com (Computing, Reviews, News) - New site / new polls / new stories! With many more to follow!
NEW LAUNCH! http://djdavid.dpscomputing.com (My DJ Website)
NEW LAUNCH! http://davidsmith.dpscomputing.com (My Personal Website)
Reply With Quote
  #4 (permalink)  
Old 21-05-2007, 12:47
Ben Ben is offline
Premium Member
 
Join Date: Jan 2007
Location: United Kingdom
Posts: 632
Send a message via AIM to Ben Send a message via MSN to Ben Send a message via Yahoo to Ben
Default

Yeah I know the problem. I tried fixing the post but the only way to display the code is using the PHP quote tags. Try editing your post flesso to this kind of quote and then all codes that aren't displaying will display:

PHP Code:
<%@ Import Namespace="System.Net.Mail" %> 
As demonstrated above all code that is not displaying will need to be quoted using PHP quote tags in order for it to display properly.

Last edited by Ben : 21-05-2007 at 12:50.
Reply With Quote
  #5 (permalink)  
Old 21-05-2007, 12:49
DPS Computing's Avatar
Premium Member
 
Join Date: Apr 2007
Location: Manchester, United Kingdom
Posts: 4,458
Send a message via ICQ to DPS Computing Send a message via AIM to DPS Computing Send a message via MSN to DPS Computing Send a message via Yahoo to DPS Computing Send a message via Skype™ to DPS Computing
Default

Quote:
Originally Posted by Ben View Post
Yeah I know the problem. I tried fixing the post but the only way to display the code is using the PHP quote tags. Try editing your post flesso to this kind of quote and then all codes that aren't displaying will display:

PHP Code:
<%@ Import Namespace="System.Net.Mail" %> 
As demonstrated above section 1 under your tutorial will display using PHP quote tags.
Thank you for the fix Ben. I'm sure flesso will be along soon to fix his post .
__________________
David Smith
DPS Computing
http://www.dpscomputing.com (Computing, Reviews, News) - New site / new polls / new stories! With many more to follow!
NEW LAUNCH! http://djdavid.dpscomputing.com (My DJ Website)
NEW LAUNCH! http://davidsmith.dpscomputing.com (My Personal Website)
Reply With Quote
  #6 (permalink)  
Old 21-05-2007, 15:09
flesso's Avatar
Premium Member
 
Join Date: Mar 2007
Location: 127.0.0.1
Posts: 1,194
Default

Quote:
Originally Posted by DPS Computing View Post
Thank you for the fix Ben. I'm sure flesso will be along soon to fix his post .
All fixed.
__________________
Regards,
Josh Hold

eUKhost Blog: Over 1000 Computer Related Articles to Sink Your Teeth Into!

Super Moderator

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.
Reply With Quote
  #7 (permalink)  
Old 16-06-2007, 10:38
Junior Member
 
Join Date: Jun 2007
Posts: 29
Default SMTP Email Sending

Hi guys and thanks for the above posts.

I have been receiving an error about unable to send to non-local addresses - eg email outside of the domain. I have created the code below to fix the issue.

Create a button on the page and also a Label with the ID of 'EmailError'.

IMPORTS:
Quote:
Imports System.Net.Mail
Imports System.Net.NetworkCredential
CODE:
Quote:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim maMailfrom As New MailAddress("[FROM EMAIL]", "[FROM NAME]")
Dim maMailTo As New MailAddress("[TO EMAIL]", "[TO NAME]")
Dim mmEmail As New MailMessage(maMailfrom, maMailTo)
mmEmail.IsBodyHtml = False
mmEmail.Subject = "[SUBJECT]"
mmEmail.Body = "[MESSAGE]
Try
Dim smtpSend As New SmtpClient("smtp.[DOMAIN]")
Dim credLogin As System.Net.NetworkCredential = New System.Net.NetworkCredential("[MAIL BOX EMAIL]", "[MAIL BOX PW]")
smtpSend.Credentials = credLogin
smtpSend.Send(mmEmail)
Catch ex As Exception
EmailError.Text = ex.ToString
End Try
End Sub
Basically replace all the []'s with want you want. I hope this makes sense to you all!
__________________
Thanks

EOTB
Reply With Quote
  #8 (permalink)  
Old 16-06-2007, 14:36
DPS Computing's Avatar
Premium Member
 
Join Date: Apr 2007
Location: Manchester, United Kingdom
Posts: 4,458
Send a message via ICQ to DPS Computing Send a message via AIM to DPS Computing Send a message via MSN to DPS Computing Send a message via Yahoo to DPS Computing Send a message via Skype™ to DPS Computing
Default

Thanks for the fix eotb!
__________________
David Smith
DPS Computing
http://www.dpscomputing.com (Computing, Reviews, News) - New site / new polls / new stories! With many more to follow!
NEW LAUNCH! http://djdavid.dpscomputing.com (My DJ Website)
NEW LAUNCH! http://davidsmith.dpscomputing.com (My Personal Website)
Reply With Quote
  #9 (permalink)  
Old 10-03-2008, 10:06
Junior Member
 
Join Date: Feb 2008
Posts: 10
Default

Great tutorial... Sometimes is quite refreshing to have a helping hand when you don't know a certain thing.
Reply With Quote
  #10 (permalink)  
Old 22-03-2008, 16:03
new member
 
Join Date: Mar 2008
Posts: 4
Default

Thank you so much for this tutorial. I will study ASP soon and I started reading some things about it. I must say this is the simplest most comprehensible article about it.
---
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 22:16.

 

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by Web Hosting 3.1.0
Copyright © 2001-2008, eUKhost.com. All rights reserved.

 
Site Map

knowledgebase articles

popular blog categories