I recently had an issue where alerts were not being sent out from a MOSS 2007 server. The event log had several "Cannot Connect to Smtp Host [ENCRYPTED]" entries. Except, that instead of saying [ENCRYPTED], it was actually a bunch of Chinese and non-printable characters. My first thought was that the Smtp host name had been corrupted, but that was an incorrect conclusion.
I am going to share a little acronym I learned in the military for troubleshooting electronics that helped me solve this issue: RVAIR
Recognize. First, someone has to notice there is a problem. In my case, no alerts
Verify. Not that I can't trust users, but I must verify the problem and be able to reproduce it consistently
Analyze. Understand the issue and potential causes
Isolate. This is the most critical step. Remove all the ancilliary "stuff" and find the root cause
Repair. Fix the problem
One thing to remember about Smtp error messages is you need to see the inner exception and stack trace to get to the actual error. SharePoint doesn't output the detail you need in the event log, so to isolate the problem and get to the root cause, I wrote a little mail tester program. Basically, it takes everything else out of the equation and tests the machine's ability to send a message via Smtp. Here is the source:
//**************************************************************** /// Program /// <summary> /// A console application to test mail /// </summary> /// <remarks> /// <u>Created</u><br/> /// Author: johpow<br/> /// Date: 2/20/2007 7:08:55 AM<br/> /// <u>History</u><br/> /// Modified by: <br/> /// Date: <br/> /// Description: <br/> /// </remarks> //**************************************************************** public class Program { public static void Main(string[] args) { try { // Check arguments if (args.Length != 3) { ShowUsage(); return; } // Create message MailMessage mmMessage = new MailMessage(); mmMessage.To.Add(new MailAddress(args[2] as string)); mmMessage.From = new MailAddress(args[1] as string); mmMessage.Subject = "TestMail"; mmMessage.Body = "This is a test"; // Send message SmtpClient sc = new SmtpClient(args[0] as string); sc.Send(mmMessage); } catch (Exception ex) { Console.WriteLine(ex); } finally { //Pause Console.WriteLine(); Console.Write("Press a key >"); Console.ReadKey(); } } private static void ShowUsage() { Console.WriteLine("Usage"); Console.WriteLine("TestMail [SmtpServer] [FromAddress] [ToAddress]"); } } // end Program
When I used the TestMail utility, I finally got to the root error:
An established connection was aborted by the software in your host machine
More helpful than "Cannot connect to Smtp Host," wouldn't you say? So that isolated it down to a firewall or anti-virus software blocking the Smtp port (25). As it turns out it was anti-virus software. The point is, you can see how by analyzing the problem, determining potential causes, and ruling them out one by one, you get to the root cause.
I have used this mail tester utility several times troubleshooting Smtp connection, relay and authentication issues from applications. I hope this simple utility is something you'll consider adding to your toolkit, along with RVAIR. The source code and the utility are attached to this post.
THANNNNNNXXXXXXXX!!!!!!!!!!