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

Problem clearing send error in email program

P: n/a
Trying to send groups of email with program using System.Net.Mail. I
do not clear MailMessage but repeatedly loop changing only the Bcc
entries. Works fine if all addresses are valid. As a simple test I
have attempted to send a valid address, then an invalid address which
my ISP (Comcast) will reject immediately as "Not our customer". I
catch the exception, display and then continue looping to send several
additional valid. The balance all are "caught" and display the an
error but they are sent. I have negligible knowledge of exceptions
but suspect I need to clear.

loop through the following changing only the bcc
try
smtpobject.Send(MyMailMsg)
Catch ex as Exception
msgbox(ex.tostring)
end try

Appreciate as usual,

Ed
Feb 19 '08 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Ed Bitzer wrote:
Trying to send groups of email with program using System.Net.Mail. I
do not clear MailMessage but repeatedly loop changing only the Bcc
entries. Works fine if all addresses are valid. As a simple test I
have attempted to send a valid address, then an invalid address which
my ISP (Comcast) will reject immediately as "Not our customer". I
catch the exception, display and then continue looping to send several
additional valid. The balance all are "caught" and display the an
error but they are sent. I have negligible knowledge of exceptions
but suspect I need to clear.

loop through the following changing only the bcc
try
smtpobject.Send(MyMailMsg)
Catch ex as Exception
msgbox(ex.tostring)
end try

Appreciate as usual,

Ed
It looks to me like you need to reset MyMailMsg if there is an exception. The
exception will not persist past the end of the try block.
Feb 19 '08 #2

P: n/a
Ed,

Can you show the full loop, because in my idea can this not be the base of
your problem.

Cor

Feb 19 '08 #3

P: n/a
On Mon, 18 Feb 2008 21:53:33 -0500, Ed Bitzer wrote:
Trying to send groups of email with program using System.Net.Mail. I
do not clear MailMessage but repeatedly loop changing only the Bcc
entries. Works fine if all addresses are valid. As a simple test I
have attempted to send a valid address, then an invalid address which
my ISP (Comcast) will reject immediately as "Not our customer". I
catch the exception, display and then continue looping to send several
additional valid. The balance all are "caught" and display the an
error but they are sent. I have negligible knowledge of exceptions
but suspect I need to clear.

loop through the following changing only the bcc
try
smtpobject.Send(MyMailMsg)
Catch ex as Exception
msgbox(ex.tostring)
end try

Appreciate as usual,

Ed
Ed,

Post a copy of the entire loop. There are ways you can structure the loop
and the error handler to be more robust to exceptions
--
http://www.thinkersroom.com/bytes
Feb 19 '08 #4

P: n/a
"Mr. Arnold" <MR. Ar****@Arnold.comschrieb:
>Trying to send groups of email with program using System.Net.Mail. I do
not clear MailMessage but repeatedly loop changing only the Bcc entries.
Works fine if all addresses are valid. As a simple test I have attempted
to send a valid address, then an invalid address which my ISP (Comcast)
will reject immediately as "Not our customer". I catch the exception,
display and then continue looping to send several additional valid. The
balance all are "caught" and display the an error but they are sent. I
have negligible knowledge of exceptions but suspect I need to clear.

loop through the following changing only the bcc
try
smtpobject.Send(MyMailMsg)
>Catch ex as Exception
msgbox(ex.tostring)
ex = null
or
ex = nothing 'don't know about that one for sure
No, that doesn't make sense. 'Try...Catch' as used in the OP's sample is
OK.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 19 '08 #5

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:O3**************@TK2MSFTNGP05.phx.gbl...
"Mr. Arnold" <MR. Ar****@Arnold.comschrieb:
>>Trying to send groups of email with program using System.Net.Mail. I do
not clear MailMessage but repeatedly loop changing only the Bcc entries.
Works fine if all addresses are valid. As a simple test I have
attempted to send a valid address, then an invalid address which my ISP
(Comcast) will reject immediately as "Not our customer". I catch the
exception, display and then continue looping to send several additional
valid. The balance all are "caught" and display the an error but they
are sent. I have negligible knowledge of exceptions but suspect I need
to clear.

loop through the following changing only the bcc
try
smtpobject.Send(MyMailMsg)
>>Catch ex as Exception
msgbox(ex.tostring)
ex = null
or
ex = nothing 'don't know about that one for sure

No, that doesn't make sense. 'Try...Catch' as used in the OP's sample is
OK.
I disagree with you, because I have used both methods to clear the Exception
to keep an application running when it would have stopped on the try/catch
while it was in a processing loop, particularly when processing many methods
within the processing loop and method calling other methods and all of them
having Try/Catches to prevent it from blowing up on the try/catch above it.

This method was used to look for a particular Exception in a multiple
Exceptions try/catch, and if I got the Exception to report the Exception to
a log, clear the Exception and let the processing flow back to the top of
the loop and continue process, otherwise, throw the Exception in each
method above it until it got to the top Try/Catch and terminate the
application.

I have used the method in C# and VB.Net solution with the try/catch and in
VB.Net with the Error GoTo.

Feb 19 '08 #6

P: n/a
deleted a bit to the thread to shorten, comment at bottom
>>>Catch ex as Exception
msgbox(ex.tostring)
ex = null
or
ex = nothing 'don't know about that one for sure

No, that doesn't make sense. 'Try...Catch' as used in the OP's
sample is OK.

I disagree with you, because I have used both methods to clear the
Exception to keep an application running when it would have stopped
on the try/catch while it was in a processing loop, particularly
when processing many methods within the processing loop and method
calling other methods and all of them having Try/Catches to prevent
it from blowing up on the try/catch above it.

This method was used to look for a particular Exception in a
multiple Exceptions try/catch, and if I got the Exception to report
the Exception to a log, clear the Exception and let the processing
flow back to the top of the loop and continue process, otherwise,
throw the Exception in each method above it until it got to the top
Try/Catch and terminate the application.

I have used the method in C# and VB.Net solution with the try/catch
and in VB.Net with the Error GoTo.
I tried and ex = null constant is no longer supported
ex= nothing ok but error repeated even for valid messages which were
sent.

I have included more extensive code as requested - appreciate your
taking a look.

Ed

\
Feb 19 '08 #7

P: n/a
"Mr. Arnold" <MR. Ar****@Arnold.comschrieb:
>>>Trying to send groups of email with program using System.Net.Mail. I do
not clear MailMessage but repeatedly loop changing only the Bcc
entries. Works fine if all addresses are valid. As a simple test I
have attempted to send a valid address, then an invalid address which
my ISP (Comcast) will reject immediately as "Not our customer". I catch
the exception, display and then continue looping to send several
additional valid. The balance all are "caught" and display the an error
but they are sent. I have negligible knowledge of exceptions but
suspect I need to clear.

loop through the following changing only the bcc
try
smtpobject.Send(MyMailMsg)

Catch ex as Exception
msgbox(ex.tostring)
ex = null
or
ex = nothing 'don't know about that one for sure

No, that doesn't make sense. 'Try...Catch' as used in the OP's sample is
OK.

I disagree with you, because I have used both methods to clear the
Exception to keep an application running when it would have stopped on the
try/catch while it was in a processing loop
If you are catching the exception inside the loop it won't stop the loop.
Setting the exception variable to 'Nothing' doesn't have any influence if
you are using 'Catch ex As <exception type>'.
This method was used to look for a particular Exception in a multiple
Exceptions try/catch, and if I got the Exception to report the Exception
to a log, clear the Exception
You do not have to "clear" exceptions. They are not bubbled up if they are
caught and not rethrown.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 19 '08 #8

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:eU**************@TK2MSFTNGP03.phx.gbl...
"Mr. Arnold" <MR. Ar****@Arnold.comschrieb:
>>>>Trying to send groups of email with program using System.Net.Mail. I
do not clear MailMessage but repeatedly loop changing only the Bcc
entries. Works fine if all addresses are valid. As a simple test I
have attempted to send a valid address, then an invalid address which
my ISP (Comcast) will reject immediately as "Not our customer". I
catch the exception, display and then continue looping to send several
additional valid. The balance all are "caught" and display the an
error but they are sent. I have negligible knowledge of exceptions
but suspect I need to clear.
>
loop through the following changing only the bcc
try
smtpobject.Send(MyMailMsg)

Catch ex as Exception
msgbox(ex.tostring)
ex = null
or
ex = nothing 'don't know about that one for sure

No, that doesn't make sense. 'Try...Catch' as used in the OP's sample
is OK.

I disagree with you, because I have used both methods to clear the
Exception to keep an application running when it would have stopped on
the try/catch while it was in a processing loop

If you are catching the exception inside the loop it won't stop the loop.
Setting the exception variable to 'Nothing' doesn't have any influence if
you are using 'Catch ex As <exception type>'.
>This method was used to look for a particular Exception in a multiple
Exceptions try/catch, and if I got the Exception to report the Exception
to a log, clear the Exception

You do not have to "clear" exceptions. They are not bubbled up if they
are caught and not rethrown.
Look man, you can't tell me something that I have done myself. This is
totally ridiculous, particularly when I have done it.
Feb 19 '08 #9

P: n/a
"Mr. Arnold" <MR. Ar****@Arnold.comschrieb:
>>>>>Trying to send groups of email with program using System.Net.Mail. I
>do not clear MailMessage but repeatedly loop changing only the Bcc
>entries. Works fine if all addresses are valid. As a simple test I
>have attempted to send a valid address, then an invalid address which
>my ISP (Comcast) will reject immediately as "Not our customer". I
>catch the exception, display and then continue looping to send
>several additional valid. The balance all are "caught" and display
>the an error but they are sent. I have negligible knowledge of
>exceptions but suspect I need to clear.
>>
>loop through the following changing only the bcc
>try
> smtpobject.Send(MyMailMsg)
>
>Catch ex as Exception
> msgbox(ex.tostring)
ex = null
or
ex = nothing 'don't know about that one for sure

No, that doesn't make sense. 'Try...Catch' as used in the OP's sample
is OK.

I disagree with you, because I have used both methods to clear the
Exception to keep an application running when it would have stopped on
the try/catch while it was in a processing loop

If you are catching the exception inside the loop it won't stop the loop.
Setting the exception variable to 'Nothing' doesn't have any influence if
you are using 'Catch ex As <exception type>'.
>>This method was used to look for a particular Exception in a multiple
Exceptions try/catch, and if I got the Exception to report the Exception
to a log, clear the Exception

You do not have to "clear" exceptions. They are not bubbled up if they
are caught and not rethrown.

Look man, you can't tell me something that I have done myself. This is
totally ridiculous, particularly when I have done it.
Well, just show me where the behavior you describe is specified and/or show
me a code sample that is a proof of what you are saying.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 19 '08 #10

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uL**************@TK2MSFTNGP05.phx.gbl...
"Mr. Arnold" <MR. Ar****@Arnold.comschrieb:
>>>>>>Trying to send groups of email with program using System.Net.Mail. I
>>do not clear MailMessage but repeatedly loop changing only the Bcc
>>entries. Works fine if all addresses are valid. As a simple test I
>>have attempted to send a valid address, then an invalid address
>>which my ISP (Comcast) will reject immediately as "Not our
>>customer". I catch the exception, display and then continue looping
>>to send several additional valid. The balance all are "caught" and
>>display the an error but they are sent. I have negligible knowledge
>>of exceptions but suspect I need to clear.
>>>
>>loop through the following changing only the bcc
>>try
>> smtpobject.Send(MyMailMsg)
>>
>>Catch ex as Exception
>> msgbox(ex.tostring)
> ex = null
> or
> ex = nothing 'don't know about that one for sure
>
No, that doesn't make sense. 'Try...Catch' as used in the OP's sample
is OK.

I disagree with you, because I have used both methods to clear the
Exception to keep an application running when it would have stopped on
the try/catch while it was in a processing loop

If you are catching the exception inside the loop it won't stop the
loop. Setting the exception variable to 'Nothing' doesn't have any
influence if you are using 'Catch ex As <exception type>'.

This method was used to look for a particular Exception in a multiple
Exceptions try/catch, and if I got the Exception to report the
Exception to a log, clear the Exception

You do not have to "clear" exceptions. They are not bubbled up if they
are caught and not rethrown.

Look man, you can't tell me something that I have done myself. This is
totally ridiculous, particularly when I have done it.

Well, just show me where the behavior you describe is specified and/or
show me a code sample that is a proof of what you are saying.
Sorry man, it's not my job. I got enough to do on the job. And just because
you say that something cannot happen doesn't make it so. One can think
outside the box and apply something. I have done it on more than a few
occasions to think outside the box have someone comeback and tell that they
didn't know that could be done, which I have been doing programming wise
since 1980. :)

:)

Feb 20 '08 #11

P: n/a
"Mr. Arnold" <MR. Ar****@Arnold.comschrieb:
>>>>>>>Trying to send groups of email with program using System.Net.Mail.
>>>I do not clear MailMessage but repeatedly loop changing only the
>>>Bcc entries. Works fine if all addresses are valid. As a simple
>>>test I have attempted to send a valid address, then an invalid
>>>address which my ISP (Comcast) will reject immediately as "Not our
>>>customer". I catch the exception, display and then continue looping
>>>to send several additional valid. The balance all are "caught" and
>>>display the an error but they are sent. I have negligible
>>>knowledge of exceptions but suspect I need to clear.
>>>>
>>>loop through the following changing only the bcc
>>>try
>>> smtpobject.Send(MyMailMsg)
>>>
>>>Catch ex as Exception
>>> msgbox(ex.tostring)
>> ex = null
>> or
>> ex = nothing 'don't know about that one for sure
>>
>No, that doesn't make sense. 'Try...Catch' as used in the OP's
>sample is OK.
>
I disagree with you, because I have used both methods to clear the
Exception to keep an application running when it would have stopped on
the try/catch while it was in a processing loop

If you are catching the exception inside the loop it won't stop the
loop. Setting the exception variable to 'Nothing' doesn't have any
influence if you are using 'Catch ex As <exception type>'.

This method was used to look for a particular Exception in a multiple
Exceptions try/catch, and if I got the Exception to report the
Exception to a log, clear the Exception

You do not have to "clear" exceptions. They are not bubbled up if they
are caught and not rethrown.

Look man, you can't tell me something that I have done myself. This is
totally ridiculous, particularly when I have done it.

Well, just show me where the behavior you describe is specified and/or
show me a code sample that is a proof of what you are saying.

Sorry man, it's not my job. I got enough to do on the job. And just
because you say that something cannot happen doesn't make it so. One can
think outside the box and apply something. I have done it on more than a
few occasions to think outside the box have someone comeback and tell that
they didn't know that could be done, which I have been doing programming
wise since 1980. :)
Well, that's nothing more than a proof that you are older than me, but it's
not a proof that you are right.

I am really wondering what you want to archieve by setting the variable 'ex'
to 'Nothing' if the exception is already caught and not rethrown. This
won't prevent it from bubbling up because it doesn't bubble up in this case
at all.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 20 '08 #12

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:u$**************@TK2MSFTNGP06.phx.gbl...
"Mr. Arnold" <MR. Ar****@Arnold.comschrieb:
>>>>>>>>Trying to send groups of email with program using
>>>>System.Net.Mail. I do not clear MailMessage but repeatedly
>>>>loop changing only the Bcc entries. Works fine if all
>>>>addresses are valid. As a simple test I have attempted to
>>>>send a valid address, then an invalid address which my ISP
>>>>(Comcast) will reject immediately as "Not our customer". I
>>>>catch the exception, display and then continue looping to
>>>>send several additional valid. The balance all are "caught"
>>>>and display the an error but they are sent. I have
>>>>negligible knowledge of exceptions but suspect I need to
>>>>clear.
>>>>>
>>>>loop through the following changing only the bcc
>>>>try
>>>> smtpobject.Send(MyMailMsg)
>>>>
>>>>Catch ex as Exception
>>>> msgbox(ex.tostring)
>>> ex = null
>>> or
>>> ex = nothing 'don't know about that one for sure
>>>
>>No, that doesn't make sense. 'Try...Catch' as used in the
>>OP's sample is OK.
>>
>I disagree with you, because I have used both methods to clear
>the Exception to keep an application running when it would have
>stopped on the try/catch while it was in a processing loop
>
If you are catching the exception inside the loop it won't stop
the loop. Setting the exception variable to 'Nothing' doesn't
have any influence if you are using 'Catch ex As <exception
type>'.
>
>This method was used to look for a particular Exception in a
>multiple Exceptions try/catch, and if I got the Exception to
>report the Exception to a log, clear the Exception
>
You do not have to "clear" exceptions. They are not bubbled up
if they are caught and not rethrown.

Look man, you can't tell me something that I have done myself.
This is totally ridiculous, particularly when I have done it.

Well, just show me where the behavior you describe is specified
and/or show me a code sample that is a proof of what you are
saying.

Sorry man, it's not my job. I got enough to do on the job. And just
because you say that something cannot happen doesn't make it so.
One can think outside the box and apply something. I have done it
on more than a few occasions to think outside the box have someone
comeback and tell that they didn't know that could be done, which I
have been doing programming wise since 1980. :)

Well, that's nothing more than a proof that you are older than me,
but it's not a proof that you are right.

I am really wondering what you want to archieve by setting the
variable 'ex' to 'Nothing' if the exception is already caught and
not rethrown. This won't prevent it from bubbling up because it
doesn't bubble up in this case at all.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
I have been testing this afternoon with the loop described and shown
here again with the additional line setting the return value to ""
Try
smtpError = false
smtpObj.Send(MyMailMsg)
Catch ex as Exception
returnValue = ex.GetBaseException.toString()
msgBox(returnvalue,,"Returned Server Response")
smtpError = true
logBatchArray(batchNum) = returnValue
returnValue = ""
End Try

I have carefully stepped through the code and monitored the MyMailMsg
structure as I attempted to send a valid address, then a invalid and
then another valid and the addresses have appeared in MyMailMsg.bcc
when I check just after the line SmtpObj.Send(MyMailMsg) yet the third
address, definitely a valid address, activates the Catch. So setting
returnValue = "" has not solved my problem.

Ed
Feb 20 '08 #13

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:u$**************@TK2MSFTNGP06.phx.gbl...
"Mr. Arnold" <MR. Ar****@Arnold.comschrieb:
>>>>>>>>Trying to send groups of email with program using System.Net.Mail.
>>>>I do not clear MailMessage but repeatedly loop changing only the
>>>>Bcc entries. Works fine if all addresses are valid. As a simple
>>>>test I have attempted to send a valid address, then an invalid
>>>>address which my ISP (Comcast) will reject immediately as "Not our
>>>>customer". I catch the exception, display and then continue
>>>>looping to send several additional valid. The balance all are
>>>>"caught" and display the an error but they are sent. I have
>>>>negligible knowledge of exceptions but suspect I need to clear.
>>>>>
>>>>loop through the following changing only the bcc
>>>>try
>>>> smtpobject.Send(MyMailMsg)
>>>>
>>>>Catch ex as Exception
>>>> msgbox(ex.tostring)
>>> ex = null
>>> or
>>> ex = nothing 'don't know about that one for sure
>>>
>>No, that doesn't make sense. 'Try...Catch' as used in the OP's
>>sample is OK.
>>
>I disagree with you, because I have used both methods to clear the
>Exception to keep an application running when it would have stopped
>on the try/catch while it was in a processing loop
>
If you are catching the exception inside the loop it won't stop the
loop. Setting the exception variable to 'Nothing' doesn't have any
influence if you are using 'Catch ex As <exception type>'.
>
>This method was used to look for a particular Exception in a multiple
>Exceptions try/catch, and if I got the Exception to report the
>Exception to a log, clear the Exception
>
You do not have to "clear" exceptions. They are not bubbled up if
they are caught and not rethrown.

Look man, you can't tell me something that I have done myself. This is
totally ridiculous, particularly when I have done it.

Well, just show me where the behavior you describe is specified and/or
show me a code sample that is a proof of what you are saying.

Sorry man, it's not my job. I got enough to do on the job. And just
because you say that something cannot happen doesn't make it so. One can
think outside the box and apply something. I have done it on more than a
few occasions to think outside the box have someone comeback and tell
that they didn't know that could be done, which I have been doing
programming wise since 1980. :)

Well, that's nothing more than a proof that you are older than me, but
it's not a proof that you are right.

I am really wondering what you want to archieve by setting the variable
'ex' to 'Nothing' if the exception is already caught and not rethrown.
This won't prevent it from bubbling up because it doesn't bubble up in
this case at all.
Yes, I remember now. I was throwing the Exception all the way back to the
top to the try/catch that was in the loop.
Then I looked at it with catches in the try, and if it was that one I wanted
to ignore, I just cleared the Exception and didn't throw it and just let the
program stay in the loop. Otherwise, the other catch was caught, and I throw
it there to make it come back to the top try/catch to log the message and
stop the program.

Yes, I caught it where it happened to log a message, and then I would throw
the Exception and brought it all the way back to the top, to look at it. It
was a long time ago back in 2005 when I did it to let the Windows service
application to continue processing or make the service stop.


Feb 20 '08 #14

P: n/a
I apologize to the group. The original problem was failure to clear
an array and while I thought I was sending one address at a time I was
progressively adding to MailMessage's bcc array/structure (actually
called something else which escapes me). Therefore only the first
batch was clean, the second failed logically but actaully was sending
a good and a bad, and the third failed even though a good address
becuase the bcc array now inclued two good and one bad. However to
further confuse me I kept changing my code attempting to create new
object to insure "cleanliness" and tried setting my
System.Net.Mail.SmtpClient to nothing. When that did not work I got
caught up in the suggestion to introduce the ex = nothing code and my
testing proved nothing because I left a line clearing the
System.Net.Mail.Smtp Client elsewhere. I just found the mistake, the
loop is working fine and I further tested, with or without the line of
ex = nothing (in my case returnValue = "") and it is not needed.

I really had panicked after spending so many hours building this
program for the community and all of a sudden finding what appeared to
be an unsolvable flaw.

Ed

Feb 20 '08 #15

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:u$**************@TK2MSFTNGP06.phx.gbl...
>
I am really wondering what you want to archieve by setting the variable
'ex' to 'Nothing' if the exception is already caught and not rethrown.
This won't prevent it from bubbling up because it doesn't bubble up in
this case at all.
As I don't recall all the way, I had multiple catches in the try/catch with
one the last catch(Exception as ex). I think I had to clear the Exception
that was caught on the Exception above the last one which was just the
general catch any exception.

I know I had to do something, because it was being caught and thrown when I
wanted it to fall through. I never use the Finally as that has caused other
problems in some cases.

Feb 20 '08 #16

P: n/a
Ed,

I am glad you wrote this, I did not see the problem, however without your
message I maybe would have taken some time in it.

Thanks for notifying us.

Cor

Feb 20 '08 #17

This discussion thread is closed

Replies have been disabled for this discussion.