I
InsightNexus

Azure Communication Email client library for Python — Azure SDK for Python 2.0.0 documentation

Author

David Craig

Published Feb 16, 2026

This package contains a Python SDK for Azure Communication Services for Email.

Key concepts¶

The Azure Communication Email package is used to do following:

  • Send emails to multiple types of recipients

  • Query the status of a sent email message

Getting started¶

Installing¶

Install the Azure Communication Email client library for Python with pip:

pip install azure-communication-email

Examples¶

EmailClient provides the functionality to send email messages .

Authentication¶

Email clients can be authenticated using the connection string acquired from an Azure Communication Resource in the Azure Portal.

from azure.communication.email import EmailClientconnection_string = "endpoint="client = EmailClient.from_connection_string(connection_string);

Email clients can also be authenticated using an AzureKeyCredential.

from azure.communication.email import EmailClientfrom azure.core.credentials import AzureKeyCredentialcredential = AzureKeyCredential("<api_key>")endpoint = ""client = EmailClient(endpoint, credential);

Send an Email Message¶

To send an email message, call the send function from the EmailClient.

content = EmailContent( subject="This is the subject", plain_text="This is the body", html= "<html><h1>This is the body</h1></html>",)address = EmailAddress(email="", display_name="Customer Name")message = EmailMessage( sender="", content=content, recipients=EmailRecipients(to=[address]) )response = client.send(message)

Send an Email Message to Multiple Recipients¶

To send an email message to multiple recipients, add a object for each recipient type and an object for each recipient.

content = EmailContent( subject="This is the subject", plain_text="This is the body", html= "<html><h1>This is the body</h1></html>",)recipients = EmailRecipients( to=[ EmailAddress(email="", display_name="Customer Name"), EmailAddress(email="", display_name="Customer Name 2"), ], cc=[ EmailAddress(email="", display_name="CC Customer Name"), EmailAddress(email="", display_name="CC Customer Name 2"), ], bcc=[ EmailAddress(email="", display_name="BCC Customer Name"), EmailAddress(email="", display_name="BCC Customer Name 2"), ] )message = EmailMessage(sender="", content=content, recipients=recipients)response = client.send(message)

Send Email with Attachments¶

Azure Communication Services support sending email with attachments.

import base64content = EmailContent( subject="This is the subject", plain_text="This is the body", html= "<html><h1>This is the body</h1></html>",)address = EmailAddress(email="", display_name="Customer Name")with open("C://readme.txt", "r") as file: file_contents = file.read()file_bytes_b64 = base64.b64encode(bytes(file_contents, 'utf-8'))attachment = EmailAttachment( name="attachment.txt", attachment_type="txt", content_bytes_base64=file_bytes_b64.decode())message = EmailMessage( sender="", content=content, recipients=EmailRecipients(to=[address]), attachments=[attachment] )response = client.send(message)

Get Email Message Status¶

The result from the send call contains a message_id which can be used to query the status of the email.

response = client.send(message)status = client.get_sent_status(response.message_id)

Troubleshooting¶

Email operations will throw an exception if the request to the server fails. The Email client will raise exceptions defined in Azure Core.

from azure.core.exceptions import HttpResponseErrortry: response = email_client.send(message)except HttpResponseError as ex: print('Exception:') print(ex)

Next steps¶

Indices and tables¶

Developer Documentation