15 49.0138 8.38624 1 0 4000 1 https://vladtalkstech.com 300 1
theme-sticky-logo-alt

Send Email from PowerShell in Office 365

2 Comments

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.

Send Email from PowerShell

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!

Send Email from PowerShell in Office 365

Follow me on Social Media and Share this article with your friends!

Leave a comment and don’t forget to like the Vlad Talks Tech Page   on Facebook and to follow me on Twitter here  for the latest news and technical articles on SharePoint.  I am also a Pluralsight author, and you can view all the courses I created on my author page.
Previous Post
Announcing the Winners of the SharePoint Fest DC
Next Post
Free Webinar: Creating Dynamic Forms in SharePoint Online Without Any Need for Technical Skills with KWizCom Forms

2 Comments

  • August 30, 2016 at 6:34 pm
    Andrew

    Is it possible to pass in a variable for the Subject the way you do for a body? It doesn’t look like it likes anything with a dollar sign in there.

    Reply

Leave a Reply