If somebody like the post and its helpful in your work then, add comments.

Monday, April 24, 2017

Office 365 : send email from SharePoint Online using CSOM PowerShell


Below script:

Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
  
$username = "[UserName]"
$securePassword = ConvertTo-SecureString "[Password]" -AsPlainText -Force
       
$spoCred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$context = New-Object Microsoft.SharePoint.Client.ClientContext("[https://[XXXXXXXXXXXXXXXXXX]/")
$context.Credentials = $spoCred                                                                
$toEmail ="[Email1]","[Email2]"  
$toSubject ="[Subject]"
$toBody ="[BODY]"       

[String[]]$email =  $toEmail
$emailProperties = New-Object Microsoft.SharePoint.Client.Utilities.EmailProperties

write-host  $emailProperties
$emailProperties.To = $email
$emailProperties.CC = [String[]]("[Email]")
$emailProperties.From = "[Email]"
$emailProperties.Subject = $toSubject
$emailProperties.Body = $toBody
[Microsoft.SharePoint.Client.Utilities.Utility]::SendEmail($context,$emailProperties)
$context.ExecuteQuery()  
                        

No comments:

Post a Comment