Share via

unable to send email

Glenn Maxwell 13,511 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 cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.

Exchange | Exchange Server | Other
Exchange | Exchange Server | Other

A robust email, calendaring, and collaboration platform developed by Microsoft, designed for enterprise-level communication and data management.Miscellaneous topics that do not fit into specific categories.

Exchange | Exchange Server | Management
Exchange | Exchange Server | Management

The administration and maintenance of Microsoft Exchange Server to ensure secure, reliable, and efficient email and collaboration services across an organization.

Exchange | Hybrid management
Exchange | Hybrid management

The administration of a hybrid deployment that connects on-premises Exchange Server with Exchange Online, enabling seamless integration and centralized control.


Answer accepted by question author
  1. Aholic Liang-MSFT 13,921 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. 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

  2. Glenn Maxwell 13,511 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

Your answer

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