Created
January 20, 2017 07:55
-
-
Save janegilring/66da6aa538900489c7162459dcfb0846 to your computer and use it in GitHub Desktop.
Script for sending an e-mail via Office 365 (requires a valid Office 365 user with an Exchange mailbox). Useful for different scenarios, such as sending e-mail from an Azure Automation runbook.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$MailParameters = @{ | |
From = 'Office 365 User <office365-user@domain.com>' | |
To = 'external-user@outlook.com' | |
Subject = 'Test from PowerShell' | |
Body = "Hello World" | |
SmtpServer = 'smtp.office365.com' | |
Port = '587' | |
Credential = Get-Credential -UserName office365-user@domain.com -Message 'Specify Office 365 user credential' | |
UseSsl = $true | |
} | |
Send-MailMessage @MailParameters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tnjkannan It seems to be authentication/authorization issues for the user specified. However, note the following statement from the Send-MailMessage documentation:
One alternative approach I commonly see and use is calling Logic Apps from PowerShell (Invoke-RestMethod) in order to send e-mails via Office 365/Exchange Online.
Here is a great tutorial for doing so.