Pages

Monday, May 19, 2014

Verify SPUtility.SendMail is working or not

Generally once we configure the Incoming/Outgoing Mail settings in Central Admin, we assume that now from SharePoint Object Model we can send an mail. For this we use the SPUtility.SendMail Method, but in some cases it fails and mail will not be send. In order to verify as a quick step, you can do send an email from Powershell using the same Namespace and Method. If this works fine, then it is 99% sure that it works from our Code.


$email = "test@sharepoint.com"
$subject = "Verify Send Mail"
$body = "Hello..Welcome to SharePoint"

$site = New-Object Microsoft.SharePoint.SPSite "http://sharepoint"
$web = $site.OpenWeb()
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web,0,0,$email,$subject,$body)

// A True or False will confirm the message has been sent or not

No comments:

Post a Comment