PowerShell script to test SharePoint Send Mail

Thought it would be good to share some of my script to the public

Copy the below script and save as .ps1 file. Run it in SharePoint Management Shell with Admin Rights.

$webUrl = Read-Host "Enter SharePoint Web Url, e.g. https://sharepoint.com"

$web = Get-SPWeb $webUrl;

 $header = New-Object System.Collections.Specialized.StringDictionary
 $to = Read-Host "Enter Email TO address (e.g. abc@def.com) "
 $subject = Read-Host "Enter Email Subject "

$body = Read-Host "Enter Email Body Content "
 $sent = [Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web,$header,$body);
 Write-Host -f Green "Email ($to) Sent successfully"
 Write-Host -f Red "Email failed to send"

Leave a Reply

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

AlphaOmega Captcha Classica  –  Enter Security Code