473,322 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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
9 3381
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
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
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
Thanks,
Dec 25 '07 #5
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: kk | last post by:
Hi Guys, i am posting a cpp program contains runtime error, memory not allocated to char *x in class B. while accessing showx function it doesn't print values. if anybody knows send a reply plz....
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
2
by: MLH | last post by:
I cut a mail function off the m'soft site. Has always worked. However, I would like to include error codes returned by the sendmail Fn and be able to understand what they mean. I had my first...
1
by: Hennie7863 | last post by:
Hi all, At this moment I'm trying to get database mail working. According to some people it should be easy. Well...that is not the case for me. I'm having the following error: The mail could...
2
by: clevrmnkey | last post by:
I've had nothing but trouble from the System.Net.Mail objects, but I finally need to make them work, and I can't for the life of me see what I'm doing wrong. I pared back my mail transaction to...
2
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used,...
2
by: swapnilsane | last post by:
Hi All, I have written following asp.net code to send email. Dim mailClient As New SmtpClient("mail.yahoo.com") Dim Msg As New MailMessage() mailClient.Host = "mail.yahoo.com"...
2
by: Danny | last post by:
Hi all, Trying to send mail with System.Net.SmtpClient, using very simple code just for testing: SmtpClient smtp = new SmtpClient("mail.server.com", 25); smtp.Credentials = new...
5
by: Don Quijote de Nicaragua | last post by:
Hi, everyone I try to send a simple e-mail witch this Code, but always send me a error messages: "ERROR: Failure sending mail." Thansk You. Don Quijote de Nicaragua. Elder Soto. Dim correo As...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.