In order to automate some tasks in Office 365 with PowerShell, sometimes you may want to send a confirmation email or a daily report by email. Luckily, there is an easy PowerShell cmdlet called “Send-MailMessage” that allows you to send an email with Exchange Server. You can also do that in Office 365, but you need to specify an important parameter: The Port number. Office 365 only accepts emails on Port 587 and secured by SSL.
So the code to send an email is pretty easy:
$cred = get-credential $body = “Just a test email” Send-MailMessage -To vlad@demo.com -from noreply@demo.com -Subject 'test' -Body $body -BodyAsHtml -smtpserver smtp.office365.com -usessl -Credential $cred -Port 587
If you want to learn more about PowerShell for Office 365, check out my Pluralsight course by clicking the banner below!
The post Send Email from PowerShell in Office 365 appeared first on Absolute SharePoint Blog by Vlad Catrinescu.
by Vlad Catrinescu via Absolute SharePoint Blog by Vlad Catrinescu
No comments:
Post a Comment