Monday, August 24, 2015

Configure SMTP Service to Queue Outgoing Emails for Testing

Testing SharePoint Designer workflows that send emails can be a pain for developers because the SharePoint farm's outgoing email settings needs to be properly configured (usually in a development environment by using the Windows Server SMTP service locally on the farm) yet we don't actually want emails to get sent to real end users while testing the workflow.
 
One option is to turn off the local SMTP service the SharePoint farm is configured to leverage for sending emails. The problem with this option is the workflow will log the error "The e-mail message cannot be sent. Make sure the outgoing e-mail settings for the server are configured correctly."  Yes, this does prevent users from getting spammed but it also prevents the workflow from continuing on to other steps and doesn't give you, the workflow developer, any means of evaluating the contents of the email.
 
Here is a better option. The premise with this option is that we setup the development SharePoint farm to use a local SMTP service which won't affect anyone else but we misconfigure the SMTP service so that it isn't actually able to transmit outbound emails. Instead it only queues the outbound emails as individual files on the file system. This gives us the ability to see when each email is "sent", though unsuccessfully, and also allows us to examine the contents of each email so that we can evaluate whether the workflow sent the emails as expected.  The assumption here is that you have already added the SMTP role to the server.
 
Here are the steps:
  1. Open IIS 6.0 on SMTP server
  2. Right click on SMTP node and choose Properties
  3. On the Access tab:
    1. Click Relay button
    2. Choose the "Only the list below" option
    3. Add IP of all SharePoint servers that should be allowed to send emails through this SMTP server
  4. On the Delivery tab:
    1. Click Advanced button
    2. Enter [0.0.0.0] in the Smart Host field (include the square brackets or you'll get an error that it can't resolve the name)
    3. Make sure "Attempt direct delivery before sending to the smart host" option is unchecked
  5. Test SMTP service
    1. On the SMTP server or other computer with the Telnet client installed send a test email using these instructions: http://technet.microsoft.com/en-us/library/bb123686(v=exchg.150).aspx (Step 3)
    2. On the SMTP server, open Explorer to the default SMTP queue folder, typically located at C:\inetpub\mailroot\Queue.  All emails should be saved as text files in this folder. You can open them using Notepad or using Outlook so you don't have to parse the text version of the email visually.