PowerShell Office 365: SMTP Email Sent with PowerShell via Office 365

In this example, I have an extremely simple function called MyCode. The purpose of the function is only to demonstrate us taking any PowerShell output then passing it ot the body of an email and sending that email.

Here is a look at the output:

Once we have the output from MyCode it is all about how we pass that over to the email. That is achieved by using Send-MailMessage.

There are a lot of required parameters when using Send-EmailMessage so using a hash table called mailprops is a simple and tidy approach to doing that.

Once mailprops is loaded, we will assign the content of that to a variable called $body

This means all that is left to do is send an email and authenticate. Give it a try yourself

Alan

 

Related Post

Call Office 365 Service Communications API and Ret... In part 4, we will now look to create the flow that will populate the nested folder called Live Updates. More information on the folder structure in p...
Powershell Office 365: Building a Hash Table and a... Here is a script that will quickly tell you some mailbox information and some mailbox statistics for an Exchange Online such as Office 365 mailbox. Th...
Call O365 Endpoints Web Service and Return the Lat... Now we will look into an automated process that allows us to call the Office 365 IP Address and URL Web service and to have the news Endpoints returne...
PowerShell SharePoint: Installing SharePoint Onlin... Once upon a time there was a need to download an MSI and to install the SharePoint PowerShell Module that way, however, as all useful and trusted modu...