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 `_\ , a `Communication Service Resource `_\ , and an `Email Communication Resource `_ with an active `Domain `_.
To create these resource, you can use the `Azure Portal `_\ , the `Azure PowerShell `_\ , or the `.NET management client library `_.
Installing
^^^^^^^^^^
Install the Azure Communication Email client library for Python with `pip `_\ :
.. code-block:: bash
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 `_.
.. code-block:: python
from azure.communication.email import EmailClient
connection_string = "endpoint=https://.communication.azure.com/;accessKey="
client = EmailClient.from_connection_string(connection_string);
Alternatively, you can also use Active Directory authentication using DefaultAzureCredential.
.. code-block:: python
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://.communication.azure.com"
client = EmailClient(endpoint, DefaultAzureCredential())
Email clients can also be authenticated using an `AzureKeyCredential `_.
.. code-block:: python
from azure.communication.email import EmailClient
from azure.core.credentials import AzureKeyCredential
credential = AzureKeyCredential("")
endpoint = "https://.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.
.. code-block:: python
message = {
"content": {
"subject": "This is the subject",
"plainText": "This is the body",
"html": "html>This is the body