unable to send email

Glenn Maxwell 11,416 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 'svcacct@contoso.com' -To 'user1@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.

Microsoft Exchange Online
Exchange Server
Exchange Server
A family of Microsoft client/server messaging and collaboration software.
1,298 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,533 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,635 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
2,105 questions
{count} votes

Accepted answer
  1. Aholic Liang-MSFT 13,856 Reputation points Microsoft Vendor
    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 'svcacct@contoso.com' -To 'user1@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

1 additional answer

Sort by: Most helpful
  1. Glenn Maxwell 11,416 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  'svcacct@contoso.com' -To ' user1@contoso.com ' -Subject 'Test' -Port 587 STARTTLS

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

    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.