How To Test SMTP Server Using PowerShell

Today, I am writing about how to test a SMTP Server by sending a Test email using a PowerShell Script in SharePoint 2010, 2013, 2016.

This blog will describe to you how we can identify and confirm that our outgoing configured email on SharePoint Central Admin is working or not.

There are very simple steps to check this. We can check the SMTP Server by using the below script.

  • Login to the Sharepoint Server either Application or Front-end.

  • Open PowerShell ISE with Administrator permission and copy the below-given script.

    1. If((Get - PSSnapin | where {  
    2.     $_.Name - match "SharePoint.PowerShell"  
    3. }) - eq $null) {  
    4.     Add - PSSnapin Microsoft.SharePoint.PowerShell  
    5. }  
    6. Clear - Host  
    7. Start - SPAssignment - global  
    8. $email = "[email protected]"  
    9. $subject = "Test subject"  
    10. $body = "Test body"  
    11. $site = New - Object Microsoft.SharePoint.SPSite "http://dca-site-80:90/"  
    12. $web = $site.OpenWeb()[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web, 0, 0, $email, $subject, $body)  
    13. Stop - SPAssignment - global 
  • The first line of script will add PowerShell SharePoint Snapin so that the Windows PowerShell can call Sharepoint Commands.
  • Clear the host and start assignments to avoid the memory leak.

  • Now, the remaining is the Variable to call and start finality. Here, you can change Email, Subject, Body and SharePoint site as you require.

  • Once you are ready with the script, press F5 on PowerShell Window. See the below image for more details.

  • Once you are done, you will be getting a True message if your SMTP server name is configured properly.

  • Promptly we will get an email from the SharePoint Server, for which we have already mentioned the subject and body.

Ebook Download
View all
Learn
View all