Azure Email Communication Services sending email via SmtpClient how to set the MessageId?

Andrei B 50 Reputation points
2025-06-19T09:08:14.53+00:00

Hello,

We are currently implementing Azure Communication Services in our application via SmtpClient. Everything is working ok but we got to the point where we want to receive events to an webhook endpoint in order to mark the emails as bounced.

The problem is that in the documentation there is no way to set the message id(for example setting a header like: X-Message-Id) or to get it after sending the email.

Is there any way to do this without using the SDK since we have a general implementation for using multiple providers and it is using SmtpClient.

Thanks!

Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
1,241 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bhargavi Naragani 6,055 Reputation points Microsoft External Staff Moderator
    2025-06-19T10:24:50.3866667+00:00

    Hi @Andrei B,

    Azure Communication Services' Email feature does support webhooks for events such as delivery, bounce, opened, etc. These are identified using the messageId which is Generated by Azure itself when you send an email. Only accessible when sending emails via the ACS SDK or REST API, because those return the messageId in the response.

    Unfortunately, when you send emails via SmtpClient, ACS doesn't expose the generated messageId back to you. Additionally, Custom headers like X-Message-Id are not recognized by ACS for tracking purposes. There’s currently no supported way to explicitly set or retrieve the messageId when using SmtpClient.

    If you need to reliably track bounces or other email events via webhooks, you will need to switch to the ACS Email SDK or REST API, at least for sending. Here's why:

    • Only the SDK/API provides the generated messageId in the response.
    • That messageId is referenced in all delivery and bounce events, allowing you to correlate sent messages with webhook payloads.
    1. Use ACS Email SDK: This is the most straightforward way:
    2. If you want to avoid SDKs, you can call the REST API directly. You’ll still receive the messageId in the JSON response. https://learn.microsoft.com/en-us/rest/api/communication/email/email/send?view=rest-communication-email-2023-03-31&tabs=HTTP

    If you're strictly limited to using SmtpClient (and not ACS SDK or API), you won’t be able to capture the messageId and therefore cannot reliably correlate events from webhooks. This is a current limitation of ACS when used via SMTP.

    https://learn.microsoft.com/en-us/answers/questions/1464206/question-about-the-message-id-when-sending-service
    https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/email/send-email-smtp/send-email-smtp?tabs=dotnet&pivots=smtp-method-smtpclient

    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.

    Let me know if you have any further Queries.


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.