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 Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

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… […]

Leave a Reply

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

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading