What is SMTP4DEV?
Well, SMTP4Dev is a nifty tool for capturing and testing Emails from any application. It doesn’t actually send any Emails to the actual recipients, but it captures Emails triggered from applications such as SharePoint. Here is how we can utilize this tool for testing outgoing Emails from SharePoint.
This is extremely helpful in development environments and for testing purposes.
Step 1: Download the SMTP4DEV Tool
Download the SMTP4DEV tool: smtp4dev, Standalone also available! Just click and run the tool.
Step 2: Set Domain name in the tool
This tool runs from the system tray area. The first thing you have to set is: configure the domain name as your current server name (by default it will be localhost).
Step 3: Configure the Outgoing Email settings in Central admin
Now in SharePoint 2013 (or in SharePoint 2010), set the outgoing email settings from SharePoint central administration site.
- Central Administration >> System Settings >> Configure outgoing e-mail settings >> add the same machine name in smtp4dev
Make sure that the domain name provided in smtp4dev tool and the Outgoing Email settings in SharePoint central Admin are same.
Step 4: Write code / Set Alerts in SharePoint to trigger E-mails
Now, You can write your custom code/event receiver/workflow/Create alerts to send Emails from SharePoint. Here is my sample code to trigger Email with SPUtililty.SendMail using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue $siteUrl ="https://intranet.crescent.com" $Web = Get-SPWeb $siteURL $mail = [Microsoft.Sharepoint.Utilities.SpUtility]::SendEmail($web,0,0,"[email protected]","Subject of the Mail","mail body")
Here is the output:
As soon as an Email triggered from SharePoint, This tiny tool starts blinking, and you should see messages appear in SMTP4Dev!
You can inspect the Email from the tool and open mails with any Email client such as Outlook.