How jitesh-raut/azure-email-communication-service-for-sending-emails works
Purpose and Entry Points
This is a small Python sample repository for sending email through Azure Communication Services (ACS). It demonstrates two independent execution paths:
• ACS Email SDK client: SendEmail_ACS_EmailClient.py
• Standard SMTP submission: SendEmail_ACS_SMTP.py
README.md is the operational guide for provisioning Azure resources, linking a verified domain, and configuring credentials.
Azure Resource and Domain Boundary
Before either sender can work, Azure infrastructure must exist: an Email Communication Service, an Azure Communication Service resource, and a verified/managed email domain connected to ACS. The sender address must belong to that connected domain.
The repository does not provision infrastructure programmatically; these are manual Azure Portal steps documented in README.md.
SDK-Based Email Send Path
SendEmail_ACS_EmailClient.py uses the Azure Communication Email Python SDK and connection-string authentication. Its primary flow is:
1. Create EmailClient from an ACS connection string.
2. Construct an email payload with sender, recipients, subject, and plaintext content.
3. Call the asynchronous begin_send operation.
4. Block on the returned poller for the send result.
This path crosses directly from the local Python runtime to the ACS Email API, with authentication bounded by the ACS connection string.
SMTP-Based Email Send Path
SendEmail_ACS_SMTP.py uses Python’s SMTP/email libraries to submit a MIME message. Its control flow is:
1. Build a multipart MIME email and populate headers/body.
2. Open an SMTP connection to ACS.
3. Upgrade the connection with STARTTLS.
4. Authenticate and submit the serialized message.
5. Close the SMTP session.
The remote SMTP boundary is smtp.azurecomm.net on port 587, with TLS 1.2+ required.
Identity and Authorization for SMTP
SMTP authentication uses Microsoft Entra application credentials rather than an ACS connection string. The SMTP username combines ACS resource name, Entra application ID, and tenant ID; the password is an Entra client secret.
The Entra service principal needs ACS permissions equivalent to Communication Services read and Email Services write. Role assignment and credential lifecycle are external Azure/Entra operational concerns described in README.md.
Data Flow and Operational Constraints
Both paths accept equivalent logical data: verified sender address, recipient address(es), subject, and message content. They differ only at the delivery transport/authentication boundary:
• SDK payload and ACS connection string: SendEmail_ACS_EmailClient.py
• MIME serialization, SMTP/STARTTLS, and Entra credentials: SendEmail_ACS_SMTP.py
Scripts are intended for local Python execution and use placeholder values that must be replaced before use. The SDK route requires the azure-communication-email package; SMTP relies on Python standard-library modules.
Main entry points: README.md Operational guide · SendEmail_ACS_EmailClient.py Send poller · SendEmail_ACS_SMTP.py SMTP sender
Components 14
Local Python
- SDK sender
SendEmail_ACS_EmailClient.py - EmailClient · Created with an ACS connection string.
SendEmail_ACS_EmailClient.py - Email payload · Sender, recipients, subject, and plaintext body.
SendEmail_ACS_EmailClient.py - Send poller · Waits for the ACS send result.
SendEmail_ACS_EmailClient.py - SMTP sender
SendEmail_ACS_SMTP.py - MIME message · Multipart message with headers and body.
SendEmail_ACS_SMTP.py
Azure Communication Services
- Verified email domain · Sender addresses must belong to this ACS-connected domain.
- ACS resource
- Email Communication Service
- ACS SMTP endpoint · smtp.azurecomm.net:587 with STARTTLS (TLS 1.2+).
- ACS role assignments · Requires Communication Services read and Email Services write permissions.
Microsoft Entra ID
- SMTP service principal · Application ID and tenant ID form part of the SMTP username.
- Client secret · Used as the SMTP password.
Other components
- Operational guide · Manual provisioning, domain linkage, roles, and credentials.
README.md
Connections 18
- Operational guide → Email Communication Service: documents provisioning
- Operational guide → ACS resource: documents provisioning
- Operational guide → Verified email domain: documents linkage
- Verified email domain → ACS resource: connected to
- SDK sender → EmailClient: creates
- SDK sender → Email payload: builds
- EmailClient → Send poller: begin_send
- Email payload → Send poller: submitted as
- Send poller → Email Communication Service: ACS Email API
- SMTP sender → MIME message: builds
- MIME message → ACS SMTP endpoint: submits over STARTTLS
- SMTP sender → ACS SMTP endpoint: opens and closes session
- SMTP service principal → Client secret: uses
- SMTP service principal → ACS SMTP endpoint: SMTP username identity
- Client secret → ACS SMTP endpoint: SMTP password
- ACS role assignments → SMTP service principal: granted to
- ACS SMTP endpoint → Email Communication Service: delivers through
- Email Communication Service → Verified email domain: uses sender domain