Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 12th, 2004, 02:27 PM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Mail not working properly

Hi there,

I am using .net Framework 1.1. I am trying to send email using vb.net(ASP.net). Using the web.mail namespace, which sends the mail fine. The problem is even though the mail gets sent, I get an error "Thread was being aborted" which means if I try email in a try...catch statement some of my code after the email code does not execute.

What is causing this error? I've tried everywhere and can't seem to find the answer, please help!

Copy of code
Try
'This works fine
objEmail = New MailMessage
            objEmail.To = ConfigurationSettings.AppSettings("adminEMail")
            objEmail.Priority = MailPriority.Normal
            objEmail.Subject = Subject
            objEmail.BodyFormat = MailFormat.Html
            objEmail.Body = Message
        objEmail.From = ConfigurationSettings.AppSettings("adminEMail")
        SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("eMailServer")
        SmtpMail.Send(objEmail)

'Exception gets thrown when try to send mail
'Any code I put here will not execute because of exception being thrown

Catch ex1 as exception
'This is where I catch the "Thread was...." error
end try
 
Old December 12th, 2004, 02:31 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Are you redirecting *after* you send the e-mail?

The Redirect method can cause a ThreadAbortion error....



Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 13th, 2004, 02:18 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I am redirecting after the email. What can I do to stop that exception then?

 
Old December 15th, 2004, 07:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Justin,

Sorry for the late response.

Redirecting can throw a ThreadAbortException. This is a known issue, and is documented here: http://support.microsoft.com/default...5BLN%5D;312629

You can code around this problem with this code:
Code:
try
{
  // Some Code
  Response.Redirect("MyPage.aspx");
}
catch (System.Threading.ThreadAbortException)
{
  // Ignore. This is not really a problem. 
  // See KB article listed earlier
}
catch(Exception ex)
{
  // Catch other errors here
}
HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Web service not working properly in IIS Abhinavnaresh ASP.NET 2.0 Professional 1 April 10th, 2008 08:53 AM
Form's calculated field not working properly PaulJH Access 11 March 5th, 2007 09:52 AM
ch 8 code is not working properly Dev_gh78 C# 1 August 4th, 2006 12:16 AM
Scheduled VBS file is not working properly bsrini SQL Server 2000 16 April 14th, 2004 04:09 AM
PreparedStatement not working properly wslyhbb Java Databases 3 September 9th, 2003 01:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.