How to Test Outgoing Emails in SharePoint using PowerShell?

While troubleshooting SharePoint Email issues, as a first step, we have to check outgoing Email settings applied on the SharePoint Central Administration site are valid. So, how to test SharePoint outgoing email quickly? Here are my PowerShell scripts to test outgoing emails in SharePoint 2013 or 2016.

Method 1: Send Email using SPUtility’s SendEmail

Call the SharePoint native SendEmail method from the SPUtility class:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$SiteURL="https://portal.crescent.com/ "
$Email = "salaudeen.rajack@crescent.com"
$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)

The above PowerShell script sends mail to the given email and returns “true” if successful.

how to test sharepoint outgoing email

Method 2: Using .Net SMTP Send Mail

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Parameters
$EmailTo = "salaudeen.rajack@crescent.com"
$Subject = "Test Email from SharePoint"
$Body = "Test Email Body"

#Get the outgoing Email Server settings
$SPGlobalAdmin = New-Object Microsoft.SharePoint.Administration.SPGlobalAdmin
$SMTPServer = $SPGlobalAdmin.OutboundSmtpServer
$EmailFrom = $SPGlobalAdmin.MailFromAddress

#Frame Email Message
$Message = new-object Net.Mail.MailMessage
$SMTP = new-object Net.Mail.SmtpClient($SMTPServer)
$Message.From = $EmailFrom
$Message.To.Add($EmailTo)
$Message.subject = $Subject
$Message.body = $Body

#Send the Email
$SMTP.Send($Message)

Method 3: Using PowerShell 3.0 Send-Mail Message

Finally, use PowerShell’s native Send-MailMessage cmdlet to validate the Outgoing Email settings.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Parameters
$EmailTo = "salaudeen.rajack@crescent.com"
$EmailSubject = "Test Email from SharePoint"
$EmailBody = "Test Email Body"

#Get the outgoing Email Server settings
$SPGlobalAdmin = New-Object Microsoft.SharePoint.Administration.SPGlobalAdmin
$SMTPServer = $SPGlobalAdmin.OutboundSmtpServer
$EmailFrom = $SPGlobalAdmin.MailFromAddress

#Using PowerShell 3.0 Send-Mail Message:
Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $EmailSubject -Body $EmailBody -BodyAsHtml -SmtpServer $SmtpServer -UseSsl

Last but not least, We may have to ensure the exchange server or SMTP accepts Emails from SharePoint servers.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

One thought on “How to Test Outgoing Emails in SharePoint using PowerShell?

  • Thanks, for your posting. It works great for all of the source codes.

    Reply

Leave a Reply

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