The SMTP server requires a secure connection or the client was not authenticated

Glenn Maxwell 12,871 Reputation points
2022-05-23T16:36:58.333+00:00

Hi All

i am using exchange 2016 hybrid environment. I am using the below syntax. i am getting the error. experts guide me
when prompted for credentials i am giving service account svc@Company portal .com. this service account is created as remote mailbox in exchange onprem and it has exchange online license.
ug@Company portal .com is a unified group and svc@Company portal .com has send as permissions on ug@Company portal .com. there is no issue with the credentials.

Send-MailMessage -SmtpServer smtp.office365.com -Credential $credential -From '******@contoso.com' -To '******@contoso.com' -Subject 'TEST' -Port 587 -UseSsl  

Error: 535 5.7.139 Authentication unsuccessful, the user credentials were incorrect.
[JIKPIOP.PROD.OUTLOOK.COM]
At line:1 char:1

  • Send-MailMessage -SmtpServer smtp.office365.com -Credential $credenti ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
  • FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,173 questions
Exchange | Exchange Server | Management
0 comments No comments
{count} votes

Accepted answer
  1. Carlos Solís Salazar 18,191 Reputation points MVP Volunteer Moderator
    2022-05-23T23:33:47.047+00:00

    Hi @Glenn Maxwell

    Thank you for asking this question on the **Microsoft Q&A Platform. **

    Check if the user has the MFA active, in that case, you must deactivate the MFA for that user,

    I cannot use MFA to send emails via PowerShell.

    Hope this helps,
    Carlos Solís Salazar

    ----------

    Accept Answer and Upvote, if any of the above helped, this thread can help others in the community looking for remediation for similar issues.
    NOTE: To answer you as quickly as possible, please mention me in your reply.



1 additional answer

Sort by: Most helpful
  1. Kael Yao 37,746 Reputation points Moderator
    2022-05-24T02:49:11.847+00:00

    Hi @Glenn Maxwell

    If SMTP auth isn't enabled in your tenant or for this service account (svc@Company portal .com), you would also receive this error: 535 5.7.139 Authentication unsuccessful, the user credentials were incorrect.
    Please refer to this link: Error: Authentication unsuccessful

    The most common cause may be security defaults is enabled in your tenant. If yes, you may need to disable it first to use SMTP auth.
    If this is not the cause, please also check the other possible causes in the link.
    For example, make sure SMTP auth is enabled for the service account, make sure MFA is disabled.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.