redirecting user when email has been sent to a thankyou page or when the email has not been send to an error page

 Hello,

I wrote this code for my email:

 Imports System.Net.Mail

Partial Class sendemail_feedbackpage
    Inherits System.Web.UI.Page

    Protected Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit.Click
        Const ToAddress = "myemail@ildw.com"
        Dim MM As New MailMessage(UsersEmail.Text, ToAddress)
        MM.Subject = "asp.netsubmission form"
        MM.Body = Body.Text

        'create a smpt class object
        Dim smpt As New SmtpClient

        smpt.Send(MM)

    End Sub
End Class

I want to be able to redirect the user to a thank you page if the mail was sent succesfully and to an error page if the email was not send.

 

Please help.

 

Mauricio

0
www
9/24/2008 7:05:16 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

8 Replies
733 Views

Similar Articles

[PageSpeed] 59

How do you define "sent successfully?"

Jeff


Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
0
jeff
9/24/2008 7:14:31 PM

The SmtpClient usually throws an exception when e-mails are not sent due to some error. So, you can use a try catch block like,

try{
      smpt.Send(MM);
      Response.Redirect("thankyou.aspx");
}
catch(Exception ex){
    Response.Redirect("error.aspx");
}

0
duttaarpan
9/24/2008 7:18:47 PM

 sucessfully means that the feedback form sent the email

0
www
9/24/2008 7:18:48 PM

 thank you but in the visual web developer says end of statement expected. I copied the code that you wrote

 

Mauricio

0
www
9/24/2008 7:29:52 PM

duttaarpan is correct, you can use a Try Catch Block.
However, the code he/she provided was in C#, so if you copied and pasted it exactly, you would get errors in your VB code.
Here it is in VB:

Try
    smtp.Send(MM)
    Response.Redirect("myThankYouPage.aspx")
Catch ex As Exception
    Response.Redirect("myEmailErrorPage.aspx")
    'or you could use:
    MyLabel.Text = "Error: " + ex
End Try
 

if (this.PostHelpedYou)
{
MarkAsAnswer();
}
0
P1ST0LPETE
9/24/2008 8:12:17 PM

 thanks for your reply but, the message is sent but anyway after it goes to the myemailerrorpage.  but I am receiving the emails

this is the code

Imports System.Net.Mail

Partial Class sendemail_feedbackpage
    Inherits System.Web.UI.Page

    Protected Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit.Click
        Const ToAddress = "myemail@ildw.com"
        Dim MM As New MailMessage(UsersEmail.Text, ToAddress)
        MM.Subject = "asp.netsubmission form"
        MM.Body = Body.Text

        'create a smpt class object
        Dim smpt As New SmtpClient

        Try
            smpt.Send(MM)
            Response.Redirect("ThankYou.aspx")
        Catch ex As Exception
            Response.Redirect("ErrorPage.aspx")
        End Try


    End Sub
End Class

0
www
9/24/2008 11:31:24 PM

Have you created both the pages, thankyou.aspx and errorpage.aspx? Check the location where they are kept and give the path correctly,

0
duttaarpan
9/25/2008 2:08:11 AM

That's because the response.redirect is throwing thread violation exception.

 You may want to try following:

Try
            smpt.Send(MM)
            Response.Redirect("ThankYou.aspx", False)
        Catch ex As Exception
            Response.Redirect("ErrorPage.aspx",false)
        End Try 

HTH


Sunny NAGI
Proper Preparation Prevents Poor Performance

Dont forget to click "Mark as Answer" on the post that helped you.
0
longhorn2005
9/25/2008 2:14:39 AM
Reply:

Similar Artilces:

User resets password (email is sent with new password) user logs in with new password how to redirect to change password page?
I have a page with the login control, another page with a reset password control and another page with a change password control. Login and reset work perfectly. However what I want is very simple. Once the user recieves the email with their new generic password I would like the next time that user logins in (using the new generic password) to automatically take them to the change password page. I am sure there is an easy way to do this and I just haven't figured it out. I am using VS2008. Thank you for your help! Shawn The simplest way would be to update the aspnet_Membership t...

Sending Email from web page-send.objmm error
when icomile the code th folowing error come .I have downloaded the code from http://www.4guysfromrolla.com/webtech/080801-1.shtml .and run it but it give me followin error . ****************************************************** The "SendUsing" configuration value is invalid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: The "SendUsing" configuration value is in...

Sending Email with Net.Mail (No Email, no error)
hi,i'm using the system.net.Mail namespace to send an email from my application. when i send, the application does not fire any exception, neither does it send the email to my account.below is the code i'm using  Dim mmailMessage As New Net.Mail.MailMessage Dim mFrom As New Net.Mail.MailAddress(mailFrom) mmailMessage.From = mFrom Dim ll As String = "myname@ourmail.com" mmailMessage.To.Add(ll) mmailMessage.Subject = "Talk Concerns" mmailMessage.Body = "Testing Concerns One Two" Dim ...

if there is some error with db should user get redirected to a general error page?
 Hi All.Lets say there is an error with inserting data to db, some server error or whatever should the user get redirected to an error page? The page i am working on is activate account so if whilst checking data with db there is a problem should the user get redirected or should the error come up on the page in question? Help please. aspd:Lets say there is an error with inserting data to db, some server error or whatever should the user get redirected to an error page?  . If some insert/ update errors happen, then it is best to provide some feedback to the user on the pag...

Know of a "Email This Page" module that actually emails the page?
I've been trying to find a module that's been written that provides the "Email This Page" functionality but instead of sending a link can actually send the content of the module/page that its linked to in the email that is sent. Also something that doesnt have to be configured for every page would be really useful.  From what I've found so far they all do the same thing and was checking to see if someone else might know of anything.  ...

contact page-sending from user email?!
Hi, May you explain to me how the contact page setting is working?I mean is the email writtin the textbox ignored and how?If so what determine the sender email and the receiver email? Take a look in the web.config at<theBeerHouse defaultConnectionStringName="LocalSqlServer"> <contactForm mailTo="thebeerhouse@wrox.com"/> <articles pageSize="10" /> <polls archiveIsPublic="true" votingLockByIP="false" /> <newsletters fromEmail="thebeerhouse@wrox.com" fromDisplayName="TheBee...

How to set up an error page that sends an email?
In my web.config file I turned custom errors on and set the defaultRedirect value to my error page.  My error page does two things: 1. It display a message "There was an error...please go back and try again or contact us....etc" 2. It sends me an email, notifying me that there was an error (and then I can check the application log for the error details) It works well, but sometimes it'll send me an email when there are no errors in the application log.  I think this is from web crawlers hitting the page so I'm going to create a robots.txt fileIs it ...

There was an error sending mail from 'bugzilla maintainer email' to 'bugzilla user email': Couldn't connect to email.company.com
hi, when users submit new tickets, they receive the this error: There was an error sending mail from 'bugzilla maintainer email' to 'bugzilla user email': Couldn't connect to email.company.com Traceback: at Bugzilla/Mailer.pm line 190 Bugzilla::Mailer::MessageToMTA(...) called at Bugzilla/BugMail.pm line 370 Bugzilla::BugMail::sendMail(...) called at Bugzilla/BugMail.pm line 272 Bugzilla::BugMail::Send(...) called at /srv/www/htdocs/bugzilla/post_bug.cgi line 226 We are running bugzilla version 4.2.1 on Linux using smtp settings with authenticated user ...

How to redirect to Error page when user try to view a page which is not authorize for him
 I have a membership provider, and it's working okey I just need to know how can I redirect a user to an error page if he try to access a page which is not allowed for his status.Example : Normal user tries to enter Url page for CreateUserAccounts which is for admins only.  what about Server.transfer? u can create a 2 class that inherits from Page: "PageForAdmin" and "PageForLogged". override oninit method and if user haven't credential to access perform a server.redirect whereever you wont. If your page inherits form PageForAdimin or PageForLog...

Email gets a send error but still goes into Sent folder. Sometimes successfully sends and sometimes doesn't
The error message we recieve sometimes on an employee's computer when sendi= ng mail reads "An error occured while sending mail. The mail server respond= ed: Resources temporarily unavailable - Please try again later. Please chec= k the message and try again" Thunderbird then proceeds to put the message in the Sent folder after hitti= ng OK, defeating the purpose of the error in my opinion. Whether or not it successfully sends is completely unknown to us unless the= person replies or the person it was emailed to is within our office; howev= er, when sending the email...

Users get redirected to login page over and over with no error...
We've got a web application that we launched about two months ago.  It uses Forms authentication with a sqlRoleProvider and a couple membership providers (ldap and a db).  Sessions are set to timieout after 60 minutes of inactivity.  99% of the time logging in after session times out works fine.  But we have a lot of users, and about 1% of the time (at least that's been reported) a user will timeout, get redirected to the login page, and when they attempt to login they just get redirected back to the login page with no error message.  I've actually...

Emailing From .net page only sends partial info.
I have a .net page that is supposed to send a very long string as a message to an email address. It works but when receiving the email only the last 1/4 of the string is there. I checked the source of the email etc. and only 1/4 of the entire string is sent. I'm using <%@ import Namespace="System.Web.Mail" %> sub emaildata(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim MyMessage as New MailMessage MyMessage.To = email.text MyMessage.From ...

Error rendering web page sent at email.
When I send a web page as email, it arrives but it doesn't render properly. The web page's resources are drawn left-justified with carriage returns. For example: Image1 Text1 Image2 Text2 Image3 Image4 Text3 The page uses Div's and CSS. for example, getting the page ... WebRequest m_WebRequest = System.Net.HttpWebRequest.Create(url); WebResponse m_WebResponse = m_WebRequest.GetResponse(); m_StreamReader = new StreamReader(m_WebResponse.GetResponseStream(),System.Text.Encoding.UTF8); HtmlBody = m_StreamReader.ReadToEnd(); then mailing...

Paging Paging Paging
I am trying to do paging with my search results and it isnt working very well. Here is what I've tried and I feel I've tried everything, lol, please help me out. Sub DataGrid1_SortCommand(Sender as object, e as DataGridSortCOmmandEventArgs) DataGrid1.DataBind() End Sub Sub Datagrid1_PageIndexChanged(Sender as object, e as DataGridPageChangedEventArgs) Dim ds as dataSet DataGrid1.CurrentPageIndex = e.NewPageIndex if Session("Search") is nothing then 'Session probably has expired, get the datasource from database Datagrid1.DataSource = ...

Web resources about - redirecting user when email has been sent to a thankyou page or when the email has not been send to an error page - asp.net.getting-started

Advertise - Redirecting - YouTube
Search Call us: 1-855-500-2756 Get started Overview Why it Works Success Stories Get Started Make Video Ads Resources This page has moved. Redirecting ...

Aboriginal funds need redirecting - report
Aboriginal funds need redirecting - report

Freedom of speech: Redirecting our society to a dangerous course
Freedom of speech: Redirecting our society to a dangerous course

Leaked Federal Government mental health report recommends redirecting $1 billion from acute hospital ...
A report commissioned by the Federal Government recommends redirecting money from acute hospital care to community-based mental health services. ...

Sona talked of redirecting voters to wrong polls, court hears in robocalls trial
Michael Sona was overheard talking about American-style campaign politics to redirect voters to the wrong polling stations in the 2011 federal ...

Unscrupulous website adverts again redirecting some users to App Store from Safari
... granting any kind of permission… In iOS 8 beta 2, Apple supposedly had remedied the issue: “Safari now blocks ads from automatically redirecting ...

Play Store May Be Redirecting Some Search Terms To The Predefined Categories
The user experience on Android is never standing still, which is no more evident than in the Play Store itself. It seems Google may be trying ...

Redirecting...
Please wait — redirecting to new Business page...

Redirecting...
Click here if you are not redirected

Redirecting Financial Flow To Asia Pacific Crucial For Region’s Sustainable Growth
... (UNEP) notes, the Asia Pacific region is home to over half of the world’s population, but much less than half its natural resources. Redirecting ...

Resources last updated: 1/9/2016 3:16:30 AM