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 'email@example.com' -To 'firstname.lastname@example.org' -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.