Hi @Pauline Leclerc,
Welcome to the Microsoft Q&A Platform!
It seems like you're facing the issue regarding email sending failures using Azure Communication Service (ACS) SMTP. The error "5.7.57 Client not authenticated to send mail. Error: 535 5.7.3 Authentication unsuccessful" indicates an authentication failure, you can try the following steps:
- Ensure the username is formatted as
<ACSResourceName>|<ClientID>|<TenantID>
. - Replace placeholders with your ACS resource name (not the full URL), Entra App Client ID, and Tenant ID.
- Check the Entra App's client secret in the Azure Portal. If expired, generate a new one.
- Ensure the secret is correctly copied without extra spaces or characters.
- Use the SMTP host provided by ACS, typically '.communications.azure.com', replace 'smtp.azurecomm.net` with the correct host from your ACS resource settings.
- Assign the "Azure Communication Services Email Sender" role to the Service Principal on the ACS resource, remove overly broad roles like Contributor, which might not grant email permissions.
- In the Azure Portal, navigate to your ACS resource > Email domains, ensure
mydomain.fr
is added and verified. If not, follow the domain verification process. - Replace
SmtpClient
with MailKit'sSmtpClient
for better logging:using MailKit.Net.Smtp; using MailKit.Security; using MimeKit; var message = new MimeMessage(); message.From.Add(new MailboxAddress("Sender", sender)); message.To.Add(new MailboxAddress("Recipient", recipient)); message.Subject = subject; message.Body = new TextPart("plain") { Text = body }; using var client = new SmtpClient(); client.Connect(smtpHostUrl, 587, SecureSocketOptions.StartTls); client.Authenticate(smtpAuthUsername, smtpAuthPassword); client.Send(message); client.Disconnect(true);
- Check logs for detailed SMTP server responses.
- Ensure outbound traffic on port 587 is allowed.
- In Azure, enable diagnostics for ACS to capture auth attempts.
- Use
openssl s_client -connect <smtp-host>:587 -starttls smtp
to manually test SMTP auth.
Hope the above provided information help in better understanding and help you resolve the issue, if you have any further concerns or queries, please feel free to reach out to us.
If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.