How to send an e-mail through Office 365 using PowerShell

This script allows to send an e-mail through Office 365 using SMTP service available in the platform. The script defines a function that encapsulates all the required parameters to be able to send an e-mail by means of Office 365 SMTP service. These parameters are used to configu

5 Star
1,824 times
Add to favorites
Office 365
E-mail Twitter Digg Facebook
  • Adding an Attachment
    1 Posts | Last post February 18, 2020
    • Thanks for sharing this. Do you happen to have this script with the option of adding an attachment/local file?
  • Just a note
    1 Posts | Last post January 31, 2020
    • I have a multifactor auth on my account and I received the "not authenticated" message.  As far as I understand it you have to use a non MFA account in order to log in like this.
  • Error
    2 Posts | Last post January 16, 2020
    • I am getting the following error when try to run this script:
      Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not 
      authenticated to send anonymous mail during MAIL FROM []
      At C:\Sources\O365ATP\PS_Send_EMail_Through_O365.ps1:28 char:9
      +         Send-MailMessage -From $sFromEMail -To $To -Cc $cc -Bcc $sBcc ...
      +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
          + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
    • Resolved: It requires Exchange Admin rights for FROM user account. 
  • Send Email through Powershell using O365
    2 Posts | Last post May 29, 2019
    • Hi Juan,
      Would you happen to have an example of how to fill in the parts needed to complete the script?
      Would be much helpful, I realize that some parts of the script give hints as to what should be there, but I am just having trouble getting it to work.  Thanks.
    • Hi Kali,
      Mosts of the parameters you have to fill are just e-mails you want to use when sending an e-mail using should be quite straightforward to complete those parameters