Share via


SharePoint: Testing Email Alerts in UAT and DEV Environments

Introduction

This post describes installing an SMTP server (SMTP4Dev) that can be used to capture all email sent from a SharePoint farm, without delivering the email to the recipients mailbox.

This is handy to have setup in a Development or UAT (user acceptance testing) environment, where you want to test or analyse email alerts sent from SharePoint, without actually having the emails delivered to the end user.

Applies To

  • SharePoint 2013
  • SharePoint 2010

The two scenarios presented here

1. Installing and configuring SMTP4Dev on a SharePoint server (or other server) that doesn’t already have a process listening on port 25 (e.g. the IIS SMTP service)
2. Installing and configuring SMTP4Dev on a SharePoint server that already has a service listening on port 25 (e.g. the IIS SMTP service)

Introduction to SMTP4Dev

SMTP4Dev is a console application used to receive email via SMTP. Email received by SMTP4Dev can be inspected or deleted. However, SMTP4Dev does not deliver email to a destination mailbox. It can listen on any port (the default port is 25), and will accept email while it’s running. It can be configure for anonymous or authenticated connections.

SMTP4Dev is great for being able to capture and analyse emails sent in a UAT or Development environment, without needing an email infrastructure (like Exchange and Outlook).

Downloaded SMTP4Dev here: http://smtp4dev.codeplex.com/ 

Installing SMTP4Dev

Installing and running SMTP4Dev is very simple. Follow these steps:

  1. Download SMTP4Dev from codeplex (http://smtp4dev.codeplex.com/) and save the zip file to the local file system. E.g. C:\Tools\smtp4dev.zip
  2. Extract the zip files contents to the same location
  3. Double click the smtp4dev.exe
  4. Done!

When SMTP4Dev is opened, it will start listening on Port 25 by default.

http://4.bp.blogspot.com/-bYJanIxvfr0/UygD5ifwieI/AAAAAAAAAFQ/3W7dXXs3aZc/s1600/smtp4dev-0.png

If there is already another process using port 25 (e.g. the IIS SMTP service), SMTP4Dev will show an error message about a socket address (the configure port is already in use).

http://4.bp.blogspot.com/-Rs1bNR2sDx0/UygECErMIJI/AAAAAAAAAFY/-A9XSyESSkI/s1600/smtp4dev-1.png

Configure SharePoint Outbound email with SMTP4Dev running on Port 25

If no other process is running on port 25, SMTP4Dev will use the default SMTP port (25) to listen on. Once you start SMTP4Dev, by default it will begin to listen  for email on port 25, using anonymous authentication.

To finish the configuration, set the Outbound Email server for the farm to the FQDN (Fully Qualified Domain Name) of the SharePoint application server running SMTP4Dev.

  1. Open the Central Admin site
  2. Click on System Settings
  3. Click on Configure outgoing e-mail settings
    http://2.bp.blogspot.com/-_2JJB0tul5Y/UygEWu7NDSI/AAAAAAAAAFg/yijdr7gFVHI/s1600/Configure-outgoing-email.png
  4. Enter the FQDN for the SharePoint application server that is running SMTP4Dev, into the Outbound SMTP Server textbox.
    http://3.bp.blogspot.com/-sMqwzkws6O8/Uy9YjqUaqhI/AAAAAAAAAF0/35wG4FAMsas/s1600/outgoing-email-2.png
  5. Set the From address and Reply-to address
  6. Click OK to save the settings.

Configure SharePoint Outbound email with SMTP4Dev running on a Custom Port

If there is already another process listening port 25, you will need to configure SMTP4Dev to listen on another port. Configuring SMTP4Dev to listen on another port is easy. However, SharePoint will only send outbound email to an SMTP server listening on Port 25. So additional configuration is required to get this working.

Configuring SMTP4Dev to listen on a custom port might happen in a scenario where all of the SharePoint servers in a UAT or Development farm already have the IIS SMTP service installed (for inbound email).
Consider the following scenario:

  • The SharePoint application server that SMTP4Dev is installed on has the host name SP13App01.mydomain.com
  • The SharePoint Application server, SP13App01.mydomain.com, already has the IIS SMTP service configured (on Port 25) for Inbound Email (functionality that allows people to email a SharePoint folder).
  • The IIS SMTP service is configured to receive email for the SharePoint farms domain alias (e.g. production-sharepoint.mydomain.com)
  • The Outbound email SMTP server for the farm is set to sp13app01.mydomain.com
  • The IIS SMTP server on sp13app01 is configured to relay email for all remote domains to the SMTP smart host going.nowhere.local, over port 19876.
  • There is a dns entry in the hosts file on sp13app01 for going.nowhere.local that uses the localhost IP address 127.0.0.1
  • SMTP4Dev is configured to listen on Port 19876

http://1.bp.blogspot.com/-7DXLLjozejk/Uy9ZH4RA0VI/AAAAAAAAAF4/2TYoGpUx24A/s1600/smtp4dev.png

In this scenario, any email sent to an address in the production-sharepoint.mydomain.com will be picked up by one of the SharePoint servers running the IIS SMTP service (on Port 25) and saved into the IIS mail Drop folder (for SharePoint to process). If an email sent to the SMTP server isn’t addressed to the production-sharepoint.mydomain.com domain, the IIS SMTP server will;

  • (WFE servers): discard the email
  • (Application server): forward (relay) the message to the SMTP smart host.

An SMTP smart host is an SMTP server that will accept email for any domain from a source SMTP server (the sending SMTP server), and forward that email to a destination SMTP server responsible for the emails domain.

In practice, the IIS SMTP on the SharePoint WFE servers should never receive email addressed to a foreign domain. However, the IIS SMTP service on the SharePoint application server will receive email addressed to the production-sharepoint.domain.com domain, as well as emails sent from the SharePoint farm itself. This is because the SharePoint server sp13app.domain.com has been set as the outgoing email server for the farm.

In this scenario, SMTP4Dev is configured as the Smarthost. It will receive all emails sent to the SharePoint Application server’s IIS SMTP service (running on Port 25) that are destined for a foreign domain (e.g. a list alert configured to send new list item alerts to a domain user).
To configure SharePoint for this type of scenario, follow these steps;

  1. Configure SMTP4Dev to listen on a custom port
  2. Add a host alias to the hosts file of the server running SMTP4Dev
  3. Configure the IIS SMTP service on the SharePoint application server to relay all email destined for a foreign domain to the host alias configured in step 2
  4. Configure the SharePoint application server as the outbound SMTP server for the farm.

Configure SMTP4Dev to listen on a custom port

  1. Open SMTP4Dev

  2. Click Options

  3. From the Options dialog, click the Server tab

  4. Change the Port Number to a custom port value between 1025 and 65000. In the example, we use port 19876

    http://3.bp.blogspot.com/-w3LFKGfQOMc/Uy-Oxcne1UI/AAAAAAAAAHM/EpPgrT71NIY/s1600/Options-server-2.png

    Note: Whatever port you choose, make sure no other process is listening on that port. To check this, you can use the NETSTAT command, and pipe the results to the FIND command. For example, so check if a process is listening on port 19786, use the following command at a command prompt.

    Netstat –a | Find “:19876”

    http://1.bp.blogspot.com/-tFL0ToDIYJ4/Uy-Oxedw67I/AAAAAAAAAHQ/bEQ_BvR0xR0/s1600/netstat-2.png

Add a host alias to the host file

Each SharePoint server in the farm is configured to send outbound email to a single SharePoint application server. The IIS SMTP service on the SharePoint application server is configured to forward (relay) all e-mail for foreign domains to a Smart Host. The “Smart Host” is actually an SMTP service (SMTP4Dev) running on itself, listening on a different port.

When you configure the Smart Host in the IIS SMTP services, the UI prevents you from adding the hostname of the current server as the Smart Host.

To work around this limitation, add an alias to the hosts file on the SharePoint application server. The alias can be anything (though it shouldn’t be a hostname used anywhere else), but the IP address must be set to the local server (127.0.0.1).

In this example, the alias is set to going.nowhere.local

http://3.bp.blogspot.com/-lqRSNaoCuEM/Uy9ZwuiKjuI/AAAAAAAAAGE/ELXbQ7GNOTE/s1600/Configure-SMTP-9.png

Configure IIS SMTP service to relay email to a Smart Host

Configure the IIS SMTP service (on the SharePoint application server) to forward email (for remote domains) to itself.

  1. Open the IIS Admin 6.0 console

  2. Expand the local server

  3. Expand the SMTP Virtual Server http://4.bp.blogspot.com/-oShdO0zkFmk/Uy9Z-BX-H0I/AAAAAAAAAGM/STn2B6L1GHc/s1600/Configure-SMTP.png

  4. Right click the virtual server, and click Properties

  5. Click on the Access tab

  6. Configure the Relay settings
    Note: Be careful configuring relay settings. Ensure that you restrict the list of servers (IP Addresses) allowed to use this server as an open (unauthenticated) SMTP relay.
    http://4.bp.blogspot.com/-1UXXS8RK_qo/Uy9aQ8YPJnI/AAAAAAAAAGU/bb2D_yDU8X8/s1600/Configure-SMTP-2.png

    http://3.bp.blogspot.com/-gFFbyn0KfPY/Uy9aZNNsF6I/AAAAAAAAAGc/520g-xB_MMo/s1600/Configure-SMTP-3.png

  7. From the example we’ve been using, we are going to allow the two SharePoint WFE servers to relay through this SMTP server un-authenticated.

  8. After configuring the SMTP Relay settings, you need to configure the Smart Host that will be used to forward all foreign email to. Click on the Delivery tab.

  9. Click Outbound connections
    http://4.bp.blogspot.com/-84mzNemNeoI/Uy9axgvniHI/AAAAAAAAAGk/Cej26D_jqlQ/s1600/Configure-SMTP-4.png

  10. In the Outbound Connections dialog, enter the TCP port that SMTP4Dev is listening on. In the example, this is port 19876
    http://1.bp.blogspot.com/-j_9BTfJtJus/Uy9a-uSHnUI/AAAAAAAAAGw/jglsvS22lKM/s1600/Configure-SMTP-5.png

  11. Click Ok to save the changes.

  12. From the Delivery tab, click Advanced.
    http://4.bp.blogspot.com/-suhWz0T29fA/Uy9a-qQL5nI/AAAAAAAAAGs/bblRMYvx7I4/s1600/Configure-SMTP-4-adv.png

  13. In the Advanced Delivery dialog, set the Smart Host. This will be the alias name you added to the hosts file. In the example, we used going.nowhere.local
    http://2.bp.blogspot.com/--le6lb1vHFs/Uy9bTxVu8PI/AAAAAAAAAG8/2uJ3T43_VMM/s1600/Configure-SMTP-8.png

  14. Click Ok to save the changes.

  15. This completes the configuration of the IIS STMP service.

Summary

  1. The IIS SMTP Service on all SharePoint servers is configured to accept emails sent to SharePoint web applications. In the examples, the SharePoint servers accept email sent to the production-sharepoint.mydomain.local domain. E.g. an email addressed to myshareddocumentlibrary@production-sharepoint.mydomain.local
  2. The IIS SMTP Service on the SharePoint application server is configured to forward all foreign email (that is, email sent to other domains) to an SMTP Smart Host (hosted on the same server), called going.nowhere.local, over port 19876.
  3. The SMTP service listening on port 19876 is SMTP4Dev.  SMTP4Dev will receive all email sent to it, so that it can be viewed. E-mail will never reach the mailbox of the intended recipient, which is the behaviour we want.

Configure the Outbound email settings for the farm

The final step is to configure the farm to send all outbound email to the SharePoint application server. After doing this, the IIS SMTP service on the SharePoint application server will receive all outbound email, and forward it on to the testing SMTP service, SMTP4Dev (listening on port 19876).

References