{"id":2402,"library":"azure-communication-email","title":"Azure Communication Email","description":"The `azure-communication-email` Python client library is part of the Azure Communication Services SDK, enabling developers to integrate email sending capabilities into their applications. It allows sending emails to single or multiple recipients, with support for plain text and HTML content, and attachments. This library helps manage email delivery status and is currently at version 1.1.0, with ongoing development as part of the broader Azure SDK for Python.","status":"active","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["Azure","email","communication","cloud","SDK"],"install":[{"cmd":"pip install azure-communication-email","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Recommended for Azure AD / Managed Identity authentication in production environments.","package":"azure-identity","optional":true}],"imports":[{"note":"The `aio` namespace is for asynchronous clients; the synchronous client is directly under `azure.communication.email`.","wrong":"from azure.communication.email.aio import EmailClient","symbol":"EmailClient","correct":"from azure.communication.email import EmailClient"},{"symbol":"EmailContent","correct":"from azure.communication.email import EmailContent"},{"symbol":"EmailRecipient","correct":"from azure.communication.email import EmailRecipient"}],"quickstart":{"code":"import os\nfrom azure.communication.email import EmailClient\nfrom azure.identity import DefaultAzureCredential\n\ntry:\n    # Authenticate using a connection string from an environment variable\n    # Alternatively, use DefaultAzureCredential for Azure AD authentication\n    connection_string = os.environ.get(\"ACS_CONNECTION_STRING\", \"\")\n    if connection_string:\n        email_client = EmailClient.from_connection_string(connection_string)\n    else:\n        # Requires azure-identity to be installed: pip install azure-identity\n        # And environment variables like AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET set\n        email_client = EmailClient(endpoint=\"https://<your-acs-resource-name>.communication.azure.com\", credential=DefaultAzureCredential())\n\n    # Replace with your actual sender and recipient addresses\n    sender_address = os.environ.get(\"SENDER_EMAIL_ADDRESS\", \"donotreply@yourverifieddomain.com\")\n    recipient_address = os.environ.get(\"RECIPIENT_EMAIL_ADDRESS\", \"recipient@example.com\")\n\n    message = {\n        \"senderAddress\": sender_address,\n        \"recipients\": {\n            \"to\": [{\"address\": recipient_address}],\n        },\n        \"content\": {\n            \"subject\": \"Hello from Azure Communication Email\",\n            \"plainText\": \"This is the plain text body of the email.\",\n            \"html\": \"<html><h1>Hello!</h1><p>This is the <b>HTML</b> body.</p></html>\"\n        }\n    }\n\n    print(\"Sending email...\")\n    poller = email_client.begin_send(message)\n    send_result = poller.result()\n\n    if send_result:\n        print(f\"Email sent successfully with ID: {send_result['id']}\")\n    else:\n        print(\"Email sending failed or result is None.\")\n\nexcept Exception as ex:\n    print(f\"Error sending email: {ex}\")\n\n","lang":"python","description":"This quickstart demonstrates sending a basic email using a connection string for authentication. For production scenarios, it is recommended to use Azure Active Directory authentication via `DefaultAzureCredential` from the `azure-identity` library. Ensure your Communication Services resource, Email Communication Services resource, and a verified domain are configured in Azure."},"warnings":[{"fix":"Update your code to use `client.begin_send()` which returns a poller. Call `poller.result()` to await the email sending outcome. Adjust property names like `sender` to `senderAddress` and `email` to `address` in your email message construction. Refer to the official changelog for specific version changes.","message":"Major breaking changes occurred around version 1.0.0, primarily shifting the `send` method to a Long-Running Operation (LRO) pattern where `client.begin_send()` returns a poller object. Direct calls to `send()` for immediate results are no longer supported. Additionally, property names like `sender` were renamed to `senderAddress`, and `email` within recipient objects to `address`.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Configure a custom domain in your Azure Email Communication Services resource. Ensure all required DNS records (SPF, DKIM, DMARC) are correctly set up in your domain provider. For significantly higher volumes, you may need to request a quota increase through Azure support.","message":"For production workloads and higher email sending limits, always use a custom domain with properly configured SPF, DKIM, and DMARC records. Azure Managed Domains are primarily intended for testing purposes and have lower sending limits, which can lead to emails being throttled or marked as spam.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install `azure-identity` (`pip install azure-identity`) and configure your environment for `DefaultAzureCredential` (e.g., Managed Identity on Azure resources, environment variables for local development). Initialize the `EmailClient` with `EmailClient(endpoint=..., credential=DefaultAzureCredential())`.","message":"While connection strings are simple for quickstarts, Microsoft recommends using Microsoft Entra ID (Azure Active Directory) authentication with `DefaultAzureCredential` for production applications. This enhances security by avoiding hardcoded secrets.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you have an Azure Communication Services resource linked to an Azure Email Communication Services resource, which in turn has a verified domain (either Azure Managed or Custom). The `senderAddress` in your email message must match a 'MailFrom' address associated with a verified domain.","message":"Email sending through Azure Communication Services requires a linked Email Communication Resource with an active, verified domain. Issues often arise from misconfigured domains or attempting to send from an unverified address.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}