By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,486 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

How to find out what type of error it is: Failure sending mail.

P: n/a
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
Dec 24 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Wrap the code in a try...catch block?
"JoeP" <No****@Hotmail.comwrote in message news:%2****************@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
Dec 24 '07 #2

P: n/a
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
Dec 24 '07 #3

P: n/a
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." <sm**@nospam.nospamwrote in message news:%2******************@TK2MSFTNGP02.phx.gbl...
Wrap the code in a try...catch block?
"JoeP" <No****@Hotmail.comwrote in message news:%2****************@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
Dec 25 '07 #4

P: n/a
Thanks,
Dec 25 '07 #5

P: n/a
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" <No****@Hotmail.comwrote in message news:eG**************@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." <sm**@nospam.nospamwrote in message news:%2******************@TK2MSFTNGP02.phx.gbl...
Wrap the code in a try...catch block?
"JoeP" <No****@Hotmail.comwrote in message news:%2****************@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
Dec 25 '07 #6

P: n/a
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" <No****@Hotmail.comwrote in message news:%2****************@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" <No****@Hotmail.comwrote in message news:eG**************@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." <sm**@nospam.nospamwrote in message news:%2******************@TK2MSFTNGP02.phx.gbl...
Wrap the code in a try...catch block?
"JoeP" <No****@Hotmail.comwrote in message news:%2****************@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
Dec 25 '07 #7

P: n/a
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." <sm**@nospam.nospamwrote in message news:OA**************@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" <No****@Hotmail.comwrote in message news:%2****************@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" <No****@Hotmail.comwrote in message news:eG**************@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." <sm**@nospam.nospamwrote in message news:%2******************@TK2MSFTNGP02.phx.gbl...
Wrap the code in a try...catch block?
"JoeP" <No****@Hotmail.comwrote in message news:%2****************@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
Dec 25 '07 #8

P: n/a
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" <No****@Hotmail.comwrote in message news:eL**************@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." <sm**@nospam.nospamwrote in message news:OA**************@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" <No****@Hotmail.comwrote in message news:%2****************@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" <No****@Hotmail.comwrote in message news:eG**************@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." <sm**@nospam.nospamwrote in message news:%2******************@TK2MSFTNGP02.phx.gbl...
Wrap the code in a try...catch block?
"JoeP" <No****@Hotmail.comwrote in message news:%2****************@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
Dec 26 '07 #9

P: n/a
Ok Thanks
"Scott M." <sm**@nospam.nospamwrote in message news:uk**************@TK2MSFTNGP06.phx.gbl...
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" <No****@Hotmail.comwrote in message news:eL**************@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." <sm**@nospam.nospamwrote in message news:OA**************@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" <No****@Hotmail.comwrote in message news:%2****************@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" <No****@Hotmail.comwrote in message news:eG**************@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." <sm**@nospam.nospamwrote in message news:%2******************@TK2MSFTNGP02.phx.gbl...
Wrap the code in a try...catch block?
"JoeP" <No****@Hotmail.comwrote in message news:%2****************@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
Dec 26 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.