Testing Email flow from your Team Foundation Server

Manoj Mohunthan brings us today’s tip…

If you have issues with TFS alerts, sometimes you would like to know if the problem is with the TFS notification settings. If you know your configuration is set correctly, then you can move on and focus on the alerts or see if they are even triggered. TFS does a pretty good job of throwing warnings/errors in the event logs if an e-mail is failing on send. I find it always best to use a simple .Net application that uses System.Net.Mail namespace to see if the problem reproduces there.

Here is a sample C# command line .EXE that you can use to test your email. Create a blank C# command line project, and paste the code below:

using System;
using System.Net;
using System.Net.Mail;

namespace TFSEmailTest
    class Sender
        public static void Main(string[] args)
                string Host = args[0];
                string FromAddress = args[1];
                string ToAddress = args[2];

                Console.WriteLine("SMTP: " + Host);
                Console.WriteLine("FromAddress: " + FromAddress);
                Console.WriteLine("ToAddress: " + ToAddress);

                SmtpClient client = new SmtpClient(Host);
                MailMessage message = new MailMessage(FromAddress,ToAddress);
                message.Body = "This is a test email";
                message.Subject = "Test Subject";

                client.UseDefaultCredentials = true;
                message.BodyEncoding = System.Text.Encoding.UTF8;


                Console.WriteLine("Email Sent");

            catch (Exception e)





Then run this application in command line logged in as the TFSService account (since this is account sending your email). You can also use RUNAS to do this, to save from having to log out/in.

TFSEmailtest <smtpservername> <fromaddress> <toaddress>


TFSEmailtest smtpservername joefrom@xyz.com joeto@xyz.com

At most times, if the email fails to send from this sample application, it would mean TFS will also fail sending an alert. This way you can take TFS out of the picture. If it does not fail, then you can focus inside TFS where you can take a TFS trace and analyze to see if your alert was triggered in the first place.

[TREVORH] Note: here at MS we are not allowed to do SEND AS, so for example I could not send email as Manoj, and vice-versa.  So, if you enter in a FROM address that does not match that of your TFS service account and it fails, that *may* be expected in your environment. Check with your SMTP admin to verify.  Also, remember that if you are running TFS as NETWORK SERVICE, your SMTP server will need to allow anonymous senders (read this for more details: http://msdn.microsoft.com/en-us/library/ms400808.aspx).



Comments (2)

  1. Usually what I find is that McAfee VirusScan has been configured to block all programs from sending email by default and that we have to add w3wp.exe to the exclude list for TFS to send email alerts.  

    Most organizations do not want to just open port 25 to any and all programs on their servers so using the above program or even telnet would not work.


Skip to main content