0

My mail program works on 2 boxes but throws "Failure sending mail" exception on the other box. This exception message is not very descriptive. Is there a way to dump the exception trace for the ease of debugging as discussed in here?

Thanks.

Community
  • 1
  • 1
itnovice
  • 503
  • 1
  • 4
  • 20
  • Wrap the bad code in a try{}catch(exception e){} and set a break point in the body of the catch. – Mark Mar 27 '15 at 17:53

1 Answers1

0

Sounds like you need to log the exception because it's running on a different box. You could look at Log4Net or Elmah

At it's simplest you can just write a text file to the file system

try
{
     // Your mail code here

}
catch (Exception ex)
{     
    System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\log.txt");
    file.WriteLine(ex.StackTrace);
    file.Close();
}

You aren't guaranteed a particularly helpful stack trace, and you might want to log other bits of information from the exception as well. Last time I encountered this problem it was firewall rules that prevented contacting the host.

ste-fu
  • 6,879
  • 3
  • 27
  • 46
  • Thanks. Does the stack trace help in the case that the SMTP traffic gets blocked by the firewall rules? – itnovice Mar 27 '15 at 20:41
  • I can't remember exactly, it was probably a message more like 'Cannot contact host'. If you want you can log every non null property of the exception to the file to help diagnose it. – ste-fu Mar 27 '15 at 20:44