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 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, 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...


3 Replies
Hi Monisha, because you're going to change settings in your exchange online environment, you first need to connect to exchange online powershell.

You can do that by running Connect-ExchangeOnline. It will ask for credentials and after successful authentication, it will import the cmdlets into your session. After that, you can continue with the Set-TransportConfig cmdlet. Grtz, Ruud

@R_Gijsbers_Rademakers , Do you mind letting me know which specific Connect-ExchangeOnline API needs to be used? I used 'Connect-ExchangeOnline -UserPrincipalName -Credential Get-Credential' and provided my credentials but received the error below. Do I need to be a managed user as mentioned below?


The user is not recognized as a managed user, or a federated user.Azure AD was not able to identify the IdP that needs
to process the user U/P: Wrong username
At C:\Program Files
(x86)\WindowsPowerShell\Modules\ExchangeOnlineManagement\3.0.0\netFramework\ExchangeOnlineManagement.psm1:726 char:21
+ throw $_.Exception.InnerException;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : The user is not recognized as a managed user, or a federated user.Azure AD was not able
to identify the IdP that needs to process the user U/P: Wrong username


Hi @monishabarooah, to be able to change the transport config setting in Exchange Online, you will need to login with an account that has the Exchange Administrator role within your tenant. Normally these roles are assigned to separate admin accounts and not to the standard user accounts. 


When you just run Connect-ExchangeOnline and hit Enter, it will ask your credentials. There's no need to specify the UserPrincipalName by using the -UserPrincipalName switch, or to use the -Credential switch.


But we should take a step back here and get a clear understanding of what you're trying to achieve and how your environment is looking like. Maybe there are other ways to send the email, for example by using a local Exchange Server if your organization has a hybrid exchange environment. Or perhaps you can use a service like Sendgrid to send out your email.


Can you elaborate a bit more about the use case your trying to solve? That would help in getting to best solution.


Br. Ruud