viewpoint-particle

Author Topic: System.Net.Mail execptions  (Read 2695 times)

mathia

  • Newbie
  • *
  • Posts: 43
System.Net.Mail execptions
« on: February 12, 2014, 10:30:17 am »
I am able to send an email using System.Net.Mail.  I would like to be able to use SmtpFailedRecipientsException in case there is a problem sending to a specific address.  I, however, don't have a clue how to get that part to work.  I can instantiate the object, but get errors trying to access any of the properties.  I am testing with a known bad email address.  How does one handle exceptions in .Net code using Winbatch?

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: System.Net.Mail execptions
« Reply #1 on: February 12, 2014, 12:17:19 pm »
You can trap errors in WinBatch using IntControl 73. The "additional error information" (in the case of CLR the exception) can be obtained using the wberroradditionalinfo variable defined when an error occurs. For more about error handling in WinBatch please read:  http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+Tutorials+Trap~Errors.txt

Unfortunately an exception doesn't get thrown in the case of a bad recipient, I have not figured out a way to capture that.
Deana F.
Technical Support
Wilson WindowWare Inc.

td

  • Tech Support
  • *****
  • Posts: 3020
    • WinBatch
Re: System.Net.Mail execptions
« Reply #2 on: February 12, 2014, 01:35:22 pm »
The very first line of the MSFT documentation for the SmtpFailedRecipientsException class states, "This API supports the .NET Framework infrastructure and is not intended to be used directly from your code."  This basically means that the class is not something that you should be trying to create in your script.

Normally, CLR exceptions are presented via the "More Error Info" box you see when WinBatch displays an error or through the wberroradditionalinfo variable as describe above when you implement your own error handling.

In this case, the CLR is not percolating the exception or any kind of error for that matter back up to WinBatch. This is either a bug in the FCL class or the documentation is incorrect and unfortunately, there isn't much that can be done to correct the problem. 

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mathia

  • Newbie
  • *
  • Posts: 43
Re: System.Net.Mail execptions
« Reply #3 on: February 12, 2014, 02:53:42 pm »
I have used that before.  Just thought that I might get some use out of some of the new .Net toys.

Thanks.