Microsoft 365 : Exchange Online / PowerShell – Resolving error – Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 Client not authenticated to send mail

Exchange admin center - Mail flow settings
Exchange admin center - Mail flow settings

Hi All,

Today new issue and solution 🙂

Details / Background

  • We have to send an email from one of our PowerShell script
  • To send an email we are using Send-MailMessage CMDLET as

PS C:\> Send-MailMessage -from $EmailFrom -To $EmailTo -Subject "Subject - LIFE IS BEAUTIFUL" -Body "LIFE IS BEAUTIFUL" -BodyAsHtml -smtpserver "smtp.office365.com" -usessl -Credential $cred -Port 587

  • While executing this “Send-MailMessage” CMDLET we were getting an issue

ISSUE / ERROR

Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 Client not authenticated to send mail. Error: 535 5.7.139
Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant. Visit https://aka.ms/smtp_auth_disabled for more information. [MA1P287CA0021.INDP287.PROD.OUTLOOK.COM
2023-02-06T14:33:38.610Z 08DB083CF80AB0C7]
At line:1 char:1

  • Send-MailMessage -from $EmailFrom -To $EmailTo -Subject “Subject – LI …
  • ~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
    • FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
fig : Microsoft 365 - PowerShell CMDLET to send email - error : Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 Client not authenticated to send mail. Error: 535 5.7.139
fig : Microsoft 365 – PowerShell CMDLET to send email – error : Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 Client not authenticated to send mail. Error: 535 5.7.139

Solution

  • There is a setting which we need to update from Exchange admin center
  • Setting – “Turn off SMTP AUTH protocol for your organization” – this setting is “ON” by default. This means – Microsoft 365 mailboxes have SMTP client authentication disabled by default.
  • So we need to enable it.

Steps to enable Microsoft 365 mailboxes SMTP client authentication

fig : Microsoft 365 - Exchange admin center
fig : Microsoft 365 – Exchange admin center
  • From left blade click on “Settings” link, we will be redirected to Exchange admin center Settings page as
fig : Microsoft 365 - Exchange admin center >> Settings
fig : Microsoft 365 – Exchange admin center >> Settings
  • From Settings blade click on setting – “Mail flow
  • Right pane will appear – “Mail flow settings” will open as
fig : Microsoft 365 - Exchange admin center >> Settings - Mail flow settings
fig : Microsoft 365 – Exchange admin center >> Settings – Mail flow settings
  • As in above figure – “Mail flow settings” – Under “Security” section uncheck the check box for setting – “Turn off SMTP AUTH protocol for your organization” – Save the respective changes
  • Once we update the above setting we will be successfully able to send the email as
fig : Microsoft 365 - Outlook - Receiving email sent through PowerShell
fig : Microsoft 365 – Outlook – Receiving email sent through PowerShell

Thanks for reading !!!

HAVE A FANTASTIC TIME AHEAD !!! LIFE IS BEAUTIFUL 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

2 Responses

  1. August 19, 2023

    […] Microsoft 365 : Exchange Online / PowerShell – PowerShell – Resolving error – Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 Client not authenticated to send mail – https://knowledge-junction.in/2023/02/07/microsoft-365-exchange-online-powershell-resolving-error-se… […]

  2. August 20, 2023

    […] Microsoft 365 : Exchange Online / PowerShell – PowerShell – Resolving error – Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 Client not authenticated to send mail – https://knowledge-junction.in/2023/02/07/microsoft-365-exchange-online-powershell-resolving-error-se… […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: