WinBatch® Technical Support Forum

Archived Boards => COM Automation and dotNet => Topic started by: mathia on February 12, 2014, 10:30:17 AM

Title: System.Net.Mail execptions
Post by: mathia 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?
Title: Re: System.Net.Mail execptions
Post by: Deana 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.
Title: Re: System.Net.Mail execptions
Post by: td 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. 

Title: Re: System.Net.Mail execptions
Post by: mathia 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.