How to test SMTP Connectivity to Microsoft 365

Microsoft 365

To test SMTP connectivity to Microsoft 365 (formerly Office 365) using PowerShell, you can use the following steps. Ensure that you have PowerShell installed on your system and that you’re running it as an administrator. Additionally, you’ll need the Exchange Online PowerShell module installed. If you haven’t already, you can install it using the following command:

PS C:\> Install-Module -Name ExchangeOnlineManagement

Dont forget to disable 2FA authentication for the account being used and the security defaults for the tenant

To test SMTP connectivity to Microsoft 365 using PowerShell in the PowerShell Integrated Scripting Environment (ISE), you can follow these steps:

  1. Open PowerShell ISE: Launch PowerShell ISE on your computer.
  2. Create a New Script: In the PowerShell ISE window, create a new script where you’ll run the SMTP connectivity test.
  3. Use PowerShell Script:You can use PowerShell commands to test SMTP connectivity in the ISE. Below is an example script that tests SMTP connectivity to Microsoft 365:
  4. Copy and paste this script into your PowerShell ISE.
  5. Run the Script: Click the “Run Script” button in the PowerShell ISE toolbar or press F5 to execute the script.
  6. Review the Output: The script will attempt to connect to the Microsoft 365 SMTP server on the specified port (in this case, port 587). If the connection is successful, it will display a success message. If there’s an issue with the connectivity, it will display an error message with details.

By following these steps, you can test SMTP connectivity to Microsoft 365 within the PowerShell ISE environment. Make sure you have an internet connection, and any firewall rules or network restrictions are configured to allow the outbound connection to Microsoft 365’s SMTP server. Additionally, ensure you have the necessary credentials if you plan to send emails via Microsoft 365.

More information can be found at this link

# Get the credential
$credential = Get-Credential

## Define the Send-MailMessage parameters
$mailParams = @{
SmtpServer = ‘smtp.office365.com’
Port = ‘587’ # or ’25’ if not using TLS
UseSSL = $true ## or not if using non-TLS
Credential = $credential
From = ‘[email protected]
To = ‘[email protected]’, ‘[email protected]
Subject = “SMTP Client Submission – $(Get-Date -Format g)”
Body = ‘This is a test email using SMTP Client Submission’
DeliveryNotificationOption = ‘OnFailure’, ‘OnSuccess’
}

## Send the message
Send-MailMessage @mailParams