Ewald’s post explains how to create a WCF web service to act as an end point for TFS Alerts. I have been using the model with a TFS 2010 to check for work item changed events, using the work item’s System.AssignedTo field to retrieve the owner of the work item (via the TFS API) so I can send an email, as well as other tasks (I know I could just send the email with a standard alert).
In TFS 2010 this worked fine, if the work item was assigned to me I got back the name richard, which I could use as the to address for the email by appending our domain name.
When I moved this WCF event receiver onto a TFS 2012 (using the TFS 2012 API) I had not expected any problems, but the emails did not arrive. On checking my logging I saw they were being sent to email@example.com. Turns out the issue was that the API call
value = this.workItem.Fields[“System.AssignedTo ”].Value.ToString();
was returning the display name ‘Richard Fennell’, which was not a valid part of the email address.
The best solution I found, thus far, was to check to see if had a display name in the AD using the method I found on stackoverflow. If I got a user name back I used that, if I got a empty string (because I have been passed a non display name) I just use the initial value assuming it is a valid address.
Seems to work but this there a easier solution?