.NET Forum / ASP.NET / General / December 2007
How to find out what type of error it is: Failure sending mail.
|
|
Thread rating:  |
JoeP - 24 Dec 2007 00:26 GMT Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Appreciate any feedback
Thanks,
Joe
Scott M. - 24 Dec 2007 01:55 GMT Wrap the code in a try...catch block?
Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Appreciate any feedback
Thanks,
Joe
JoeP - 25 Dec 2007 01:07 GMT Well I had actuallt the code like the below: The debugger poped up and just said that the Failure sending mail. and did not provide the reason. But from some reason in my computer under Visual Studio 2005, the Alert message did not pop up. Just wondering why? (The debugger did).
Thanks,
Joe
Try some code..... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody
Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Catch smtpEx As SmtpException ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email: {0}');", smtpEx.Message.Replace("'", "\'")), True)
Catch generalEx As Exception
ClientScript.RegisterStartupScript(Me.GetType(), "General Problem", String.Format("alert('There was a general problem: {0}');", generalEx.Message.Replace("'", "\'")), True)
End Try
Wrap the code in a try...catch block?
"JoeP" <NoSpam@Hotmail.com> wrote in message news:%23i4RTOcRIHA.3516@TK2MSFTNGP02.phx.gbl... Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Appreciate any feedback
Thanks,
Joe
JoeP - 25 Dec 2007 01:47 GMT Hi All,
Ok, after checking into it I had some code after the End Try and that was the reason Alert() did not pop up. Moving that code under the Try fixed the problem.
But I am trying to break the message into 2 lines:
ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email! Please call us by phone {0}');", smtpEx.Message.Replace("'", "\'")), True)
Now how do I bring the actual err line into the second line of the Alert()
There was a problem in sending the email! Please call us by phone. Unable to cast object of type 'System.Int32' to type 'System.Net.Mail.MailMessage'
Thanks,
Joe
Well I had actuallt the code like the below: The debugger poped up and just said that the Failure sending mail. and did not provide the reason. But from some reason in my computer under Visual Studio 2005, the Alert message did not pop up. Just wondering why? (The debugger did).
Thanks,
Joe
Try some code..... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody
Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Catch smtpEx As SmtpException ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email: {0}');", smtpEx.Message.Replace("'", "\'")), True)
Catch generalEx As Exception
ClientScript.RegisterStartupScript(Me.GetType(), "General Problem", String.Format("alert('There was a general problem: {0}');", generalEx.Message.Replace("'", "\'")), True)
End Try
"Scott M." <smar@nospam.nospam> wrote in message news:%23lIk0%23cRIHA.4444@TK2MSFTNGP02.phx.gbl... Wrap the code in a try...catch block?
"JoeP" <NoSpam@Hotmail.com> wrote in message news:%23i4RTOcRIHA.3516@TK2MSFTNGP02.phx.gbl... Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Appreciate any feedback
Thanks,
Joe
Scott M. - 25 Dec 2007 02:44 GMT When you are in a Catch section, notice that the exception is passed to the catch as "ex". If you check out the properties of "ex", you can find out about the exception. Start with this:
Catch ex As Exception console.writeline("Exception type is: " & ex.getType.toString) console.writeline("Exception message is: " & ex.Message)
Hi All,
Ok, after checking into it I had some code after the End Try and that was the reason Alert() did not pop up. Moving that code under the Try fixed the problem.
But I am trying to break the message into 2 lines:
ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email! Please call us by phone {0}');", smtpEx.Message.Replace("'", "\'")), True)
Now how do I bring the actual err line into the second line of the Alert()
There was a problem in sending the email! Please call us by phone. Unable to cast object of type 'System.Int32' to type 'System.Net.Mail.MailMessage'
Thanks,
Joe
"JoeP" <NoSpam@Hotmail.com> wrote in message news:eGeSbJpRIHA.5988@TK2MSFTNGP02.phx.gbl... Well I had actuallt the code like the below: The debugger poped up and just said that the Failure sending mail. and did not provide the reason. But from some reason in my computer under Visual Studio 2005, the Alert message did not pop up. Just wondering why? (The debugger did).
Thanks,
Joe
Try some code..... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody
Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Catch smtpEx As SmtpException ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email: {0}');", smtpEx.Message.Replace("'", "\'")), True)
Catch generalEx As Exception
ClientScript.RegisterStartupScript(Me.GetType(), "General Problem", String.Format("alert('There was a general problem: {0}');", generalEx.Message.Replace("'", "\'")), True)
End Try
"Scott M." <smar@nospam.nospam> wrote in message news:%23lIk0%23cRIHA.4444@TK2MSFTNGP02.phx.gbl... Wrap the code in a try...catch block?
"JoeP" <NoSpam@Hotmail.com> wrote in message news:%23i4RTOcRIHA.3516@TK2MSFTNGP02.phx.gbl... Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Appreciate any feedback
Thanks,
Joe
JoeP - 25 Dec 2007 17:42 GMT My question is now how can I concatenate the 2 strings together into the message box for the Alert()?
ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email! Please call us by phone {0}');", smtpEx.Message.Replace("'", "\'")), True)
String 1 is: 'There was a problem in sending the email! Please call us by phone! String 2 is:smtpEx.Message
Thanks.
When you are in a Catch section, notice that the exception is passed to the catch as "ex". If you check out the properties of "ex", you can find out about the exception. Start with this:
Catch ex As Exception console.writeline("Exception type is: " & ex.getType.toString) console.writeline("Exception message is: " & ex.Message)
"JoeP" <NoSpam@Hotmail.com> wrote in message news:%23XxCPgpRIHA.4476@TK2MSFTNGP06.phx.gbl... Hi All,
Ok, after checking into it I had some code after the End Try and that was the reason Alert() did not pop up. Moving that code under the Try fixed the problem.
But I am trying to break the message into 2 lines:
ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email! Please call us by phone {0}');", smtpEx.Message.Replace("'", "\'")), True)
Now how do I bring the actual err line into the second line of the Alert()
There was a problem in sending the email! Please call us by phone. Unable to cast object of type 'System.Int32' to type 'System.Net.Mail.MailMessage'
Thanks,
Joe
"JoeP" <NoSpam@Hotmail.com> wrote in message news:eGeSbJpRIHA.5988@TK2MSFTNGP02.phx.gbl... Well I had actuallt the code like the below: The debugger poped up and just said that the Failure sending mail. and did not provide the reason. But from some reason in my computer under Visual Studio 2005, the Alert message did not pop up. Just wondering why? (The debugger did).
Thanks,
Joe
Try some code..... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody
Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Catch smtpEx As SmtpException ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email: {0}');", smtpEx.Message.Replace("'", "\'")), True)
Catch generalEx As Exception
ClientScript.RegisterStartupScript(Me.GetType(), "General Problem", String.Format("alert('There was a general problem: {0}');", generalEx.Message.Replace("'", "\'")), True)
End Try
"Scott M." <smar@nospam.nospam> wrote in message news:%23lIk0%23cRIHA.4444@TK2MSFTNGP02.phx.gbl... Wrap the code in a try...catch block?
"JoeP" <NoSpam@Hotmail.com> wrote in message news:%23i4RTOcRIHA.3516@TK2MSFTNGP02.phx.gbl... Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Appreciate any feedback
Thanks,
Joe
Scott M. - 26 Dec 2007 03:01 GMT Generally, you don't want to take information from the exception and send it directly to the client as this can expose security holes & proprietary code. Instead you find out what exception you have encountered in the Try...Catch and then you write whatever you find to be appropriate to the client based on that information. If you really want to include exception information directly in your output, it is a simple matter of concatenation:
ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a {0} problem in sending the email! Please call us by phone {1}');", ex.GetType.ToString(), smtpEx.Message.Replace("'", "\'")), True)
My question is now how can I concatenate the 2 strings together into the message box for the Alert()?
ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email! Please call us by phone {0}');", smtpEx.Message.Replace("'", "\'")), True)
String 1 is: 'There was a problem in sending the email! Please call us by phone! String 2 is:smtpEx.Message
Thanks.
"Scott M." <smar@nospam.nospam> wrote in message news:OAtGO$pRIHA.4180@TK2MSFTNGP06.phx.gbl... When you are in a Catch section, notice that the exception is passed to the catch as "ex". If you check out the properties of "ex", you can find out about the exception. Start with this:
Catch ex As Exception console.writeline("Exception type is: " & ex.getType.toString) console.writeline("Exception message is: " & ex.Message)
"JoeP" <NoSpam@Hotmail.com> wrote in message news:%23XxCPgpRIHA.4476@TK2MSFTNGP06.phx.gbl... Hi All,
Ok, after checking into it I had some code after the End Try and that was the reason Alert() did not pop up. Moving that code under the Try fixed the problem.
But I am trying to break the message into 2 lines:
ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email! Please call us by phone {0}');", smtpEx.Message.Replace("'", "\'")), True)
Now how do I bring the actual err line into the second line of the Alert()
There was a problem in sending the email! Please call us by phone. Unable to cast object of type 'System.Int32' to type 'System.Net.Mail.MailMessage'
Thanks,
Joe
"JoeP" <NoSpam@Hotmail.com> wrote in message news:eGeSbJpRIHA.5988@TK2MSFTNGP02.phx.gbl... Well I had actuallt the code like the below: The debugger poped up and just said that the Failure sending mail. and did not provide the reason. But from some reason in my computer under Visual Studio 2005, the Alert message did not pop up. Just wondering why? (The debugger did).
Thanks,
Joe
Try some code..... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody
Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Catch smtpEx As SmtpException ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email: {0}');", smtpEx.Message.Replace("'", "\'")), True)
Catch generalEx As Exception
ClientScript.RegisterStartupScript(Me.GetType(), "General Problem", String.Format("alert('There was a general problem: {0}');", generalEx.Message.Replace("'", "\'")), True)
End Try
"Scott M." <smar@nospam.nospam> wrote in message news:%23lIk0%23cRIHA.4444@TK2MSFTNGP02.phx.gbl... Wrap the code in a try...catch block?
"JoeP" <NoSpam@Hotmail.com> wrote in message news:%23i4RTOcRIHA.3516@TK2MSFTNGP02.phx.gbl... Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Appreciate any feedback
Thanks,
Joe
JoeP - 26 Dec 2007 14:49 GMT Ok Thanks Generally, you don't want to take information from the exception and send it directly to the client as this can expose security holes & proprietary code. Instead you find out what exception you have encountered in the Try...Catch and then you write whatever you find to be appropriate to the client based on that information. If you really want to include exception information directly in your output, it is a simple matter of concatenation:
ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a {0} problem in sending the email! Please call us by phone {1}');", ex.GetType.ToString(), smtpEx.Message.Replace("'", "\'")), True)
"JoeP" <NoSpam@Hotmail.com> wrote in message news:eLETt1xRIHA.4180@TK2MSFTNGP06.phx.gbl... My question is now how can I concatenate the 2 strings together into the message box for the Alert()?
ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email! Please call us by phone {0}');", smtpEx.Message.Replace("'", "\'")), True)
String 1 is: 'There was a problem in sending the email! Please call us by phone! String 2 is:smtpEx.Message
Thanks.
"Scott M." <smar@nospam.nospam> wrote in message news:OAtGO$pRIHA.4180@TK2MSFTNGP06.phx.gbl... When you are in a Catch section, notice that the exception is passed to the catch as "ex". If you check out the properties of "ex", you can find out about the exception. Start with this:
Catch ex As Exception console.writeline("Exception type is: " & ex.getType.toString) console.writeline("Exception message is: " & ex.Message)
"JoeP" <NoSpam@Hotmail.com> wrote in message news:%23XxCPgpRIHA.4476@TK2MSFTNGP06.phx.gbl... Hi All,
Ok, after checking into it I had some code after the End Try and that was the reason Alert() did not pop up. Moving that code under the Try fixed the problem.
But I am trying to break the message into 2 lines:
ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email! Please call us by phone {0}');", smtpEx.Message.Replace("'", "\'")), True)
Now how do I bring the actual err line into the second line of the Alert()
There was a problem in sending the email! Please call us by phone. Unable to cast object of type 'System.Int32' to type 'System.Net.Mail.MailMessage'
Thanks,
Joe
"JoeP" <NoSpam@Hotmail.com> wrote in message news:eGeSbJpRIHA.5988@TK2MSFTNGP02.phx.gbl... Well I had actuallt the code like the below: The debugger poped up and just said that the Failure sending mail. and did not provide the reason. But from some reason in my computer under Visual Studio 2005, the Alert message did not pop up. Just wondering why? (The debugger did).
Thanks,
Joe
Try some code..... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody
Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Catch smtpEx As SmtpException ClientScript.RegisterStartupScript(Me.GetType(), "E-Mail Problem", String.Format("Alert('There was a problem in sending the email: {0}');", smtpEx.Message.Replace("'", "\'")), True)
Catch generalEx As Exception
ClientScript.RegisterStartupScript(Me.GetType(), "General Problem", String.Format("alert('There was a general problem: {0}');", generalEx.Message.Replace("'", "\'")), True)
End Try
"Scott M." <smar@nospam.nospam> wrote in message news:%23lIk0%23cRIHA.4444@TK2MSFTNGP02.phx.gbl... Wrap the code in a try...catch block?
"JoeP" <NoSpam@Hotmail.com> wrote in message news:%23i4RTOcRIHA.3516@TK2MSFTNGP02.phx.gbl... Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
Appreciate any feedback
Thanks,
Joe
Peter Bromberg [C# MVP] - 24 Dec 2007 03:32 GMT As Scott indicated, you need to learn to wire up your code with exception handling in order to be able to determine "what went wrong".
So at a minimum:
oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient
Begin Try oSMTP.Send(oMailMessage) (in this line I am getting the above err) Catch ex as Exception System.Diagnostics.Debug.WriteLine(ex.ToString() ) End Try
Sorry, I really haven't used Visual Basic for a very long time (a good thing) But you get the idea. Put a breakpoint on the Debug.WriteLine statement and you can examine the exception by hovering your mouse over the "ex" variable.
-- Peter Site: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com MetaFinder: http://www.blogmetafinder.com
> Hi All, > [quoted text clipped - 12 lines] > > Joe Scott M. - 24 Dec 2007 16:04 GMT oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient
Try oSMTP.Send(oMailMessage) (in this line I am getting the above err) Catch ex as Exception System.Diagnostics.Debug.WriteLine(ex.ToString() ) End Try
JoeP - 25 Dec 2007 01:23 GMT
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|