[SPO] Send e-mail from site using PNP
So, here goes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking #Config Parameters $AdminSiteURL = https://tenant-admin.sharepoint.com/ $EmailFrom =admin@tenant.onmicrosoft.com $EmailTo = admin2@tenant.onmicrosoft.com $Subject ="Utilities test" $SiteURL = https://tenant.sharepoint.com/sites/testsite #Setup Credentials and connect $Cred = Get-Credential Connect-SPOService -Url $AdminSiteURL -Credential $Cred #Get site info $SiteStorage = Get-SPOSite https://tenant.sharepoint.com/sites/testsite #Setup the site context for SPUtility SendEmail $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password) #Setup Email $EmailProperties = New-Object Microsoft.SharePoint.Client.Utilities.EmailProperties $EmailProperties.From = $EmailTo $EmailProperties.To = [String[]] $EmailTo $EmailProperties.Subject = $Subject $EmailProperties.Body = $SiteStorage | Convertto-html [Microsoft.SharePoint.Client.Utilities.Utility]::SendEmail($Ctx,$EmailProperties) $Ctx.ExecuteQuery() |
Enjoy!