How to Send Email with Office 365 Direct Send and PowerShell


The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

Microsoft Office 365 Direct Send enables your organization to send bulk email without having to send it through Microsoft Exchange Server. This article will walk you through how to use PowerShell and the Office 365 API using cmdlets in order by which they are listed in this article.

The “send-mailmessage office 365 the smtp server requires a secure connection” is one of the most common errors that users encounter when using Office 365 Direct Send. This error can be fixed by changing the SMTP settings in PowerShell.

How to Send Email with Office 365 Direct Send and PowerShell

Did you know that you can use PowerShell to send email from Office 365? In this article, you’ll learn how to utilize PowerShell’s Send-MailMessage cmdlet to send mail using Office 365’s SMTP services.

Check out this in-depth lesson on Send-MailMessage if you want to learn more about sending email using PowerShell.

SMTP Client Submission vs. Sending Directly

Before we dive too deep into PowerShell, keep in mind that there isn’t just one method to use PowerShell to send email using Office 365. There are two methods to send email in Office 365. Sending Directly, SMTP Client Submission, and Authenticated SMTP Submission are the available choices.

Authenticated SMTP Submission

Authenticated SMTP Submission is the easiest to set up. You would choose this option if you plan to send emails from a device or application to recipients inside and outside your organization. There is no extra action to do in Office 365 to allow this.

You may use any sender address with this option. However, the address must come from one of your approved domains.

To use Authenticated SMTP Submission, you must:

  • Have a user mailbox in Office 365? (licensed). This email address will be shown as the message’s sender.
  • must be able to be resolved and reached by PowerShell (or another client).
  • The client must open TCP Port 587 or 25 to Office 365.

Sending Directly

Ramping up the complexity a bit is the Sending Directly option. Like Authenticated SMTP Submission, Sending Directly allows you to use any sender address. Also, the from address must be from one of your verified accepted domains.

The big difference between Sending Directly and Authenticated SMTP Submission is no external recipients are allowed. If you need to send to email recipients outside of your organization, Sending Directly will not work for you.

Sending Directly has a few of its own requirements/recommendations:

  • It is not necessary for this sender address to be a legitimate mailbox. However, if you want to get NDRs or responses at this address, you’ll need it.
  • From your client to Office 365, TCP Port 25 is open.
  • Your MX endpoint URL must be able to be resolved and reached by the device (eg.
  • A public IP address that is static. This is to ensure that your SPF record is up to date and that your mails are not marked as spam (optional but recommended)

If you’re not sure where to look for your MX endpoint URL, here’s a simple guide:

  1. Go to the Office 365 Admin Portal and log in.
  2. Copy the MX Points to address or value by clicking Setup (1), Domains (2), Domain name (3), and MX Points to address or value by clicking Setup (1), Domains (2), Domain name (3), and MX Points to address or value by clicking Setup (1) (4).

Obtaining the URL for the Office 365 MX EndpointObtaining the URL for the Office 365 MX Endpoint

Authenticated SMTP Submission

The first method to send email is via SMTP Client Submission or Authenticated SMTP Submission. Using PowerShell’s Send-MailMessage cmdlet, we can provide all of the parameters we need to send email through Office 365.

You may use the snippet below to send email using this approach.

To use Send-MailMessage, you must first create a PowerShell PScredential object and then give all of the arguments it requires.

# Obtain the authorization code ## Define the Send-MailMessage parameters using $credential = Get-Credential. @ SmtpServer =’’ $mailParams = @ UseSSL = $true ## or not if using non-TLS Credential = ‘587’ # or ’25’ if not using TLS $credential ‘[email protected]’, ‘[email protected]’, ‘[email protected]’, ‘[email protected]’, ‘[email protected]’, ‘[email protected]’, ‘[email protected]’, ‘ “SMTP Client Submission – $(Get-Date -Format g)” Subject = “SMTP Client Submission – $(Get-Date -Format g)” DeliveryNotificationOption = ‘OnFailure’, ‘OnSuccess’ DeliveryNotificationOption = ‘OnFailure’, ‘OnSuccess’ ## Transmit the message @mailParams Send-MailMessage

You should get an email from both the internal recipient ( and the external domain when you execute the code above (

Message received by the internal recipientEmails sent internally

Message received by the external recipientEmail from a third party

Sending Directly (TLS Required)

Similar to Authenticated SMTP Submission, you can use nearly the same parameters for Send-MailMessage. However this time, the To recipients will only be internal.

It’s also worth noting that a PSCredential wasn’t required.

## Build parameters $mailParams = @{ SmtpServer = ‘<tenant>’ Port = ’25’ UseSSL = $true From = ‘[email protected]’ To = ‘[email protected]’ Subject = “Sending Directly $(Get-Date -Format g)” Body = ‘This is a test email using Sending Directly’ DeliveryNotificationOption = ‘OnFailure’, ‘OnSuccess’ } ## Send the email Send-MailMessage @mailParams

Message received by the internal recipient using Sending DirectlySending Directly email


As you can see, Office 365 offers two distinct ways to send email. We used PowerShell as an example to explain both in this post. However, PowerShell isn’t required. You may use any approach as long as your application or programming language supports TLS authentication.

Additional Reading

The “office 365 smtp settings” is a feature of Office 365 that allows users to send email with the service. This article will show you how to use PowerShell to send email with Office 365 Direct Send.

Frequently Asked Questions

Related Tags

  • powershell send email office 365 with credentials
  • powershell script to send email via smtp office 365
  • powershell send email office 365 without credentials
  • enable smtp authentication office 365
  • powershell send email office 365 modern authentication

Table of Content