SPS outgoing e-mail

SharePoint 2013, 2016, 2019 OnPrem

In some scenarios, developers will need to test the SharePoint configuration for outgoing emails. Usually, this check will take place before implementing C# code to send emails from SharePoint web parts. The following script can be written inside ps file and run from powershell cmd.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Configuration Parameters
$SiteURL="http://sps:portNo/"
$Email = "receiver email"
$Subject = "Test Email from SharePoint"
$Body = "Test Email Body"
 
#Get the Web
$Web = Get-SPWeb $SiteURL
 
#Send Email using SPUtility SendEmail method
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($Web ,0,0,$Email,$Subject,$Body)

Leave a Reply

Your email address will not be published. Required fields are marked *