unable to send email

Glenn Maxwell 12,871 Reputation points
2023-08-25T18:02:58.9466667+00:00

Hi All

I am trying to trigger a test email using the below syntax i am getting error. if i am using onprem relay i am not seeing any issue if i use office365 relay i am facing issue. exchange online plan1 license is assigned to the service account. sender and recipient email is my domain.

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

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, the user credentials were incorrect.

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,171 questions
Exchange Exchange Server Other
Exchange Exchange Server Management
Exchange Hybrid management
{count} votes

Accepted answer
  1. Aholic Liang-MSFT 13,886 Reputation points Microsoft External Staff
    2023-08-28T09:41:37.2533333+00:00

    Hi Glenn Maxwell,

    Please use the following command:

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

     

    Note: that the -UseTSSL switch should not use any parameters, such as STARTTLS.

     

    In addition, check the following settings for SMTP AUTH:

    1. Disabling security defaults
    2. Check if SMTP authentication is enabled for this user
    3. Exclude the user from a Conditional Access policy that blocks Legacy Authentication
    4. Disable Multi-Factor Authentication (MFA) on the licensed mailbox that's being used

    Please refer to this link for details: Fix issues with printers, scanners, and LOB apps that send email using Microsoft 365 - Exchange | Microsoft Learn


    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.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Glenn Maxwell 12,871 Reputation points
    2023-08-25T18:35:46.56+00:00

    I am getting the below error when i remove ssl

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

    The server response was: 5.7.3 STARTTLS is required to send mail

    0 comments No comments

  2. Rajesh Kumar (IT)/GG 0 Reputation points
    2024-10-23T09:29:34.89+00:00

    Send-Mailmessage : Mailbox unavailable. The server response was: 5.7.1 Unable to relay for"Email-ID"

    0 comments No comments

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.