---
title: "azure-communication-email | pypx"
description: "Microsoft Azure MyService Management Client Library for Python"
canonical_url: "https://pypx.app/packages/azure-communication-email"
meta:
  "og:description": "Microsoft Azure MyService Management Client Library for Python"
  "og:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_azure-communication-email%2Cversion_1.1.0%2Csummary_Microsoft%2BAzure%2BMyService%2BManagement%2BClient%2BLibrary%2Bfor%2BPython%2Clicense_MIT%2BLicense%2Cp_Ii9wYWNrYWdlcy9henVyZS1jb21tdW5pY2F0aW9uLWVtYWlsIg%2Cs_LxSlWTGYLbIzm7fg.png"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "azure-communication-email 1.1.0"
  "twitter:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_azure-communication-email%2Cversion_1.1.0%2Csummary_Microsoft%2BAzure%2BMyService%2BManagement%2BClient%2BLibrary%2Bfor%2BPython%2Clicense_MIT%2BLicense%2Cp_Ii9wYWNrYWdlcy9henVyZS1jb21tdW5pY2F0aW9uLWVtYWlsIg%2Cs_LxSlWTGYLbIzm7fg.png"
---

> Index of every page on this site: [llms.txt](https://pypx.app/llms.txt)

# **azure-communication-email**

v1.1.0

Microsoft Azure MyService Management Client Library for Python

63 KB Python 3.9+ py3-none-anyMIT License3 deps

[** Diff **](https://pypx.app/packages/azure-communication-email/diff)

`$ uv add azure-communication-email`

# Azure Communication Email client library for Python

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

## Key concepts

The Azure Communication Email package is used to send emails to multiple types of recipients.

## Getting started

### Prerequisites

You need an [Azure subscription](https://azure.microsoft.com/free/dotnet/), a [Communication Service Resource](https://learn.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp), and an [Email Communication Resource](https://aka.ms/acsemail/createemailresource) with an active [Domain](https://aka.ms/acsemail/domainsoverview).

To create these resource, you can use the [Azure Portal](https://learn.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp), the [Azure PowerShell](https://learn.microsoft.com/powershell/module/az.communication/new-azcommunicationservice), or the [.NET management client library](https://learn.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-net).

### Installing

Install the Azure Communication Email client library for Python with [pip](https://pypi.org/project/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](https://portal.azure.com).

```
from azure.communication.email import EmailClient

connection_string = "endpoint=https://<resource-name>.communication.azure.com/;accessKey=<Base64-Encoded-Key>"
client = EmailClient.from_connection_string(connection_string);
```

Alternatively, you can also use Active Directory authentication using DefaultAzureCredential.

```
from azure.communication.email import EmailClient
from azure.identity import DefaultAzureCredential

# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables.
endpoint = "https://<resource-name>.communication.azure.com"
client = EmailClient(endpoint, DefaultAzureCredential())
```

Email clients can also be authenticated using an [AzureKeyCredential](https://aka.ms/azsdk-python-core-azurekeycredential).

```
from azure.communication.email import EmailClient
from azure.core.credentials import AzureKeyCredential

credential = AzureKeyCredential("<api_key>")
endpoint = "https://<resource-name>.communication.azure.com/"
client = EmailClient(endpoint, credential);
```

### Send an Email Message

To send an email message, call the `begin_send` function from the `EmailClient`. This will return a poller. You can use this poller to check on the status of the operation and retrieve the result once it's finished.

```
message = {
    "content": {
        "subject": "This is the subject",
        "plainText": "This is the body",
        "html": "html><h1>This is the body</h1></html>"
    },
    "recipients": {
        "to": [
            {
                "address": "customer@domain.com",
                "displayName": "Customer Name"
            }
        ]
    },
    "senderAddress": "sender@contoso.com"
}

poller = client.begin_send(message)
result = poller.result()
```

### 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.

```
message = {
    "content": {
        "subject": "This is the subject",
        "plainText": "This is the body",
        "html": "html><h1>This is the body</h1></html>"
    },
    "recipients": {
        "to": [
            {"address": "customer@domain.com", "displayName": "Customer Name"},
            {"address": "customer2@domain.com", "displayName": "Customer Name 2"}
        ],
        "cc": [
            {"address": "ccCustomer@domain.com", "displayName": "CC Customer Name"},
            {"address": "ccCustomer2@domain.com", "displayName": "CC Customer Name 2"}
        ],
        "bcc": [
            {"address": "bccCustomer@domain.com", "displayName": "BCC Customer Name"},
            {"address": "bccCustomer2@domain.com", "displayName": "BCC Customer Name 2"}
        ]
    },
    "senderAddress": "sender@contoso.com"
}

poller = client.begin_send(message)
result = poller.result()
```

### Send Email with Attachments

Azure Communication Services support sending email with attachments.

```
import base64

with open("C://readme.txt", "r") as file:
    file_contents = file.read()

file_bytes_b64 = base64.b64encode(bytes(file_contents, 'utf-8'))

message = {
    "content": {
        "subject": "This is the subject",
        "plainText": "This is the body",
        "html": "html><h1>This is the body</h1></html>"
    },
    "recipients": {
        "to": [
            {
                "address": "customer@domain.com",
                "displayName": "Customer Name"
            }
        ]
    },
    "senderAddress": "sender@contoso.com",
    "attachments": [
        {
            "name": "attachment.txt",
            "contentType": "text/plain",
            "contentInBase64": file_bytes_b64.decode()
        }
    ]
}

poller = client.begin_send(message)
result = poller.result()
```

### Send Email with Inline Attachments

Azure Communication Services support sending inline attachments. Adding an optional `contentId` parameter to an attachment will make it an inline attachment.

```
import base64

with open("C://inline_image.jpg", "r") as file:
    file_contents = file.read()

file_bytes_b64 = base64.b64encode(bytes(file_contents, 'utf-8'))

message = {
    "content": {
        "subject": "This is the subject",
        "plainText": "This is the body",
        "html": "<html>This is the body<br /><img src=\"cid:my-inline-image\" /></html>"
    },
    "recipients": {
        "to": [
            {
                "address": "customer@domain.com",
                "displayName": "Customer Name"
            }
        ]
    },
    "senderAddress": "sender@contoso.com",
    "attachments": [
        {
            "name": "inline_image.jpg",
            "contentType": "image/jpeg",
            "contentInBase64": file_bytes_b64.decode(),
            "contentId": "my-inline-image"
        }
    ]
}

poller = client.begin_send(message)
result = poller.result()
```

## Troubleshooting

Email operations will throw an exception if the request to the server fails. The Email client will raise exceptions defined in [Azure Core](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md).

```
from azure.core.exceptions import HttpResponseError

try:
    response = client.send(message)
except HttpResponseError as ex:
    print('Exception:')
    print(ex)
```

## Next steps

- [Read more about Email in Azure Communication Services](https://aka.ms/acsemail/overview)

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com](https://cla.microsoft.com).

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

# Release History

## 1.1.0 (2025-09-01)

### Features Added

- Consumers can now provide a value for the `contentId` property when sending emails with attachments. This allows consumers to reference attachments in the email body using the `cid` scheme. The `contentId` property can be set on the `EmailAttachment` object.
- `EmailClient.begin_send` now supports an optional `operation_id` parameter.

## 1.0.1b1 (2024-08-28)

### Features Added

- Consumers can now provide a value for the `contentId` property when sending emails with attachments. This allows consumers to reference attachments in the email body using the `cid` scheme. The `contentId` property can be set on the `EmailAttachment` object.

## 1.0.0 (2023-03-31)

### Features Added

The public release of the Azure Communication Services SDK for Email has the following features:

- send emails with a variety of options (multiple recipients, attachments, etc.)
- poll for the status of the email that was sent to track its progress

## 1.0.0b2 (2023-03-01)

### Features Added

- Adding support for AAD token authentication
- Added the ability to specify the API version by an optional `api_version` keyword parameter.

### Breaking Changes

- Made the SDK Model-less. Objects are now constructed using a dictionary instead of a model.
- Reworked the SDK to follow the LRO (long running operation) approach. The 'begin\_send' method returns a poller that can be used to check for the status of sending the email and retrieve the result. The return object has been adjusted to fit this approach.
- The `get_send_status` method has been removed.
- The `sender` property has been changed to `senderAddress`.
- The `email` property under the recipient object has been changed to `address`.
- The `attachmentType` property under `attachments` has been changed to 'contentType'. This now accepts the attachment mime type.
- The `contentBytesBase64` property under `attachments` has been changed to `contentInBase64`
- Custom headers in the email message are now key/value pairs.
- The importance property was removed. Email importance can now be specified through either the `x-priority` or `x-msmail-priority` custom headers.

### Other Changes

Python 3.6 is no longer supported. Please use Python version 3.7 or later. For more details, please read our page on [Azure SDK for Python version support policy](https://github.com/Azure/azure-sdk-for-python/wiki/Azure-SDKs-Python-version-support-policy).

## 1.0.0b1 (2022-08-09)

The first preview of the Azure Communication Email Client has the following features:

- send emails to multiple recipients with attachments
- get the status of a sent message

## **Details **

<dl>

<dt>Version</dt>
<dd>1.1.0</dd>

<dt>License</dt>
<dd>MIT License</dd>

<dt>Python</dt>
<dd>&gt;=3.9</dd>

<dt>Maintainer</dt>
<dd>Microsoft Corporation</dd></dl>

## **Links**

- [Homepage](https://github.com/Azure/azure-sdk-for-python)
- [View on PyPI](https://pypi.org/project/azure-communication-email/)

## **Maintainers **

- Microsoft Corporation · [azpysdkhelp@microsoft.com](mailto:azpysdkhelp@microsoft.com)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://pypx.app/#website","@type":"WebSite","description":"The Python Package Index, reimagined. Fast search, dependency insights, download trends, and changelogs — all in one place.","name":"pypx","url":"https://pypx.app/"},{"@id":"https://pypx.app/packages/azure-communication-email#webpage","@type":"WebPage","description":"Microsoft Azure MyService Management Client Library for Python","name":"azure-communication-email","url":"https://pypx.app/packages/azure-communication-email","isPartOf":{"@id":"https://pypx.app/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://pypx.app/packages/azure-communication-email"]}]},{"@id":"https://pypx.app/packages/azure-communication-email#/schema/software-application/1","@type":"SoftwareApplication","applicationCategory":"DeveloperApplication","description":"Microsoft Azure MyService Management Client Library for Python","license":"MIT License","name":"azure-communication-email","softwareVersion":"1.1.0"}]}
```

## Sitemap

See the full [sitemap](https://pypx.app/sitemap.md) for all pages.
