Dec 14 2022 09:02 AM
Dec 14 2022 09:02 AM
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
https://aka.ms/smtp_auth_disabled for more information. [SJ0PR03CA0222.namprd03.prod.outlook.com]
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
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
On following the steps to enable SMTP Auth as mentioned in https://aka.ms/smtp_auth_disabled, 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
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...
Dec 14 2022 11:34 AM
Dec 14 2022 03:42 PM
@R_Gijsbers_Rademakers , Do you mind letting me know which specific Connect-ExchangeOnline API needs to be used? I used 'Connect-ExchangeOnline -UserPrincipalName email@example.com -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
+ 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
Dec 15 2022 12:32 AM
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.