Need info using Send-MailMessage API

Hey Folks, I have been trying to use the 'Send-MailMessage API to send emails and getting the error below.

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
Enable or disable SMTP AUTH in Exchange Online | Microsoft Learn for more information. []
At C:\vmal\Compute-Fabric-HostAgent\src\scripts\Email.ps1:36 char:19

  • … $unused = Send-MailMessage -To $To -From $from -SmtpServer $SMTPSer …
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-Mai
      lMessage], SmtpException
    • FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

On following the steps to enable SMTP Auth as mentioned in Enable or disable SMTP AUTH in Exchange Online | Microsoft Learn, I installed the ExchangeOnlineManagement module by using the command ‘Install-Module -Name ExchangeOnlineManagement’ and post that trying to use the command ‘Set-TransportConfig -SmtpClientAuthenticationDisabled $false’ but get the following error:

Set-TransportConfig -SmtpClientAuthenticationDisabled $false
Set-TransportConfig : The term ‘Set-TransportConfig’ is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At line:1 char:1

  • Set-TransportConfig -SmtpClientAuthenticationDisabled $false
  •   + CategoryInfo          : ObjectNotFound: (Set-TransportConfig:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException

Any idea why this error is showing up and how it can be resolved? Any more modules to be installed? I didnt find any in the documentation…


Welcome to the forum. :wave:t4:

Before we proceed … when you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

Please share at least the relevant code you use.

I googled for you “powershell send-mailmessage with authentication” and found the following that might help you:

It looks like you may also need to install the ExchangePowerShell module as stated here: