# Python email libraries

Python email libraries send messages through an SMTP server or an email provider's HTTP API. A provider SDK sends each message as an API request rather than through an SMTP connection to a mail server. These libraries let apps send sign-up confirmations, password resets, and receipts.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [boto3](#botothree) | 2.5B | 9.9K | Nov 2026 | Apache-2.0 |
| [Django](#django) | 52.2M | 91.8K | Nov 2026 | BSD-3-Clause |
| [SendGrid](#sendgrid) | 24.2M | 1.6K | Sep 2025 | MIT |
| [Resend](#resend) | 15.1M | 133 | Nov 2026 | MIT |
| [aiosmtplib](#aiosmtplib) | 13.0M | 438 | Sep 2026 | MIT |
| [Anymail](#django-anymail) | 4.0M | 1.9K | Sep 2026 | BSD-3-Clause |
| [Azure Communication Email](#azure-communication-email) | 3.8M | 5.6K | Oct 2025 | MIT |
| [Flask-Mail](#flask-mail-library) | 1.4M | 644 | May 2024 | BSD-3-Clause |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[SendGrid](#sendgrid) has the most monthly downloads among the dedicated email libraries in this comparison, at 24.2M.

## Capabilities

| Library | SMTP transport | Native async send |
| --- | --- | --- |
| [boto3](#botothree) | No | No |
| [Django](#django) | Yes | No |
| [SendGrid](#sendgrid) | No | No |
| [Resend](#resend) | No | Yes |
| [aiosmtplib](#aiosmtplib) | Yes | Yes |
| [Anymail](#django-anymail) | No | No |
| [Azure Communication Email](#azure-communication-email) | No | Yes |
| [Flask-Mail](#flask-mail-library) | Yes | No |

## Libraries

### boto3

[GitHub](https://github.com/boto/boto3) · [PyPI](https://pypi.org/project/boto3)

Provides the AWS SDK for Python.

- Downloads / mo: 2.5B
- Stars: 9.9K
- Last release: 1.44.6
- License: Apache-2.0
- Capabilities: [From the boto3 docs](https://github.com/boto/boto3)

```sh
python -m pip install boto3
```

**Quickstart**

```python
import boto3

ses = boto3.client("sesv2", region_name="us-east-1")
response = ses.send_email(
    FromEmailAddress="sender@example.com",
    Destination={"ToAddresses": ["recipient@example.com"]},
    Content={"Simple": {"Subject": {"Data": "Hello"},
                        "Body": {"Text": {"Data": "Hello from SES"}}}},
)

```

From [send_email.html](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sesv2/client/send_email.html) · [Find projects using boto3 →](https://dashboard.exa.ai/playground/search?q=boto3%20GitHub%20projects)

### Django

[GitHub](https://github.com/django/django) · [PyPI](https://pypi.org/project/django)

Provides a high-level Python web framework for rapid development.

- Downloads / mo: 52.2M
- Stars: 91.8K
- Last release: 6.1.3
- License: BSD-3-Clause
- Capabilities: [From the Django docs](https://github.com/django/django)

```sh
python -m pip install django
```

**wagtail/wagtail** (20.7K stars)

[wagtail/wagtail](https://github.com/wagtail/wagtail) 

```python
def send_mail(subject, message, recipient_list, from_email=None, **kwargs):
    """
    Wrapper around Django's EmailMultiAlternatives as done in send_mail().
    Custom from_email handling and special Auto-Submitted header.
    """
    if not from_email:
        if hasattr(settings, "WAGTAILADMIN_NOTIFICATION_FROM_EMAIL"):
            from_email = settings.WAGTAILADMIN_NOTIFICATION_FROM_EMAIL
        elif hasattr(settings, "DEFAULT_FROM_EMAIL"):
            from_email = settings.DEFAULT_FROM_EMAIL
        else:
            # We are no longer using the term `webmaster` except in this case, where we continue to match Django's default: https://github.com/django/django/blob/stable/3.2.x/django/conf/global_settings.py#L223
            from_email = "webmaster@localhost"

    using = kwargs.get("using")
    connection = kwargs.get("connection")

    if not connection:
        # Only pass the arguments that have been given. On Django 6.1 and above these
        # are applied on top of the mailer configuration, so passing None would replace
        # the configured username and password, leaving the backend unauthenticated.
        connection_kwargs = {}
        if kwargs.get("auth_user") is not None:
            connection_kwargs["username"] = kwargs["auth_user"]
        if kwargs.get("auth_password") is not None:
            connection_kwargs["password"] = kwargs["auth_password"]
        if kwargs.get("fail_silently"):
            connection_kwargs["fail_silently"] = kwargs["fail_silently"]

        if DJANGO_VERSION >= (6, 1) and not connection_kwargs:
            connection = mailers.default if using is None else mailers[using]
        else:
            connection = get_connection(**connection_kwargs)

    multi_alt_kwargs = {
        "headers": {
            "Auto-Submitted": "auto-generated",
        },
        "bcc": kwargs.get("bcc", None),
        "cc": kwargs.get("cc", None),
        "reply_to": kwargs.get("reply_to", None),
    }
    mail = EmailMultiAlternatives(
        subject, message, from_email, recipient_list, **multi_alt_kwargs
    )
    html_message = kwargs.get("html_message", None)
    if html_message:
        mail.attach_alternative(html_message, "text/html")

    if not mail.recipients():
        return 0
    return connection.send_messages([mail])

```

[wagtail/admin/mail.py](https://github.com/wagtail/wagtail/blob/11a50f61147218b6c940319a6911febd3434e522/wagtail/admin/mail.py#L47-L98) · [More projects using Django →](https://dashboard.exa.ai/playground/search?q=django%20GitHub%20projects)

**Quickstart**

```python
from django.core.mail import send_mail

send_mail(
    "Subject here",
    "Here is the message.",
    "from@example.com",
    ["to@example.com"],
)

```

From [email.txt](https://github.com/django/django/blob/6.1.3/docs/topics/email.txt)

### SendGrid

[GitHub](https://github.com/sendgrid/sendgrid-python) · [PyPI](https://pypi.org/project/sendgrid)

Provides the Twilio SendGrid library for Python.

- Downloads / mo: 24.2M
- Stars: 1.6K
- Last release: 6.12.5
- License: MIT
- Capabilities: [From the SendGrid docs](https://github.com/sendgrid/sendgrid-python)

```sh
python -m pip install sendgrid
```

**home-assistant/core** (92.4K stars)

[home-assistant/core](https://github.com/home-assistant/core) 

```python
def send_message(self, message: str = "", **kwargs: Any) -> None:
        """Send an email to a user via SendGrid."""
        subject = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)

        data = {
            "personalizations": [
                {"to": [{"email": self.recipient}], "subject": subject}
            ],
            "from": {"email": self.sender, "name": self.sender_name},
            "content": [{"type": CONTENT_TYPE_TEXT_PLAIN, "value": message}],
        }

        response = self._sg.client.mail.send.post(request_body=data)
        if response.status_code != HTTPStatus.ACCEPTED:
            _LOGGER.error("Unable to send notification")

```

[homeassistant/components/sendgrid/notify.py](https://github.com/home-assistant/core/blob/8dbdb49d1e2f8107688ec45257dc8ab68fd5a01f/homeassistant/components/sendgrid/notify.py#L64-L78) · [More projects using SendGrid →](https://dashboard.exa.ai/playground/search?q=sendgrid%20GitHub%20projects)

**Quickstart**

```python
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail

client = SendGridAPIClient(os.environ["SENDGRID_API_KEY"])
response = client.send(Mail(
    from_email="from@example.com", to_emails="to@example.com",
    subject="Hello", html_content="<strong>Hello from SendGrid</strong>",
))

```

From [README.rst](https://pypi.org/pypi/sendgrid/6.12.5/json#info.description)

### Resend

[GitHub](https://github.com/resend/resend-python) · [PyPI](https://pypi.org/project/resend)

Provides the Python SDK for Resend.

- Downloads / mo: 15.1M
- Stars: 133
- Last release: 2.55.0
- License: MIT
- Capabilities: [From the Resend docs](https://github.com/resend/resend-python)

```sh
python -m pip install resend
```

**airweave-ai/airweave** (6.5K stars)

[airweave-ai/airweave](https://github.com/airweave-ai/airweave) 

```python
def _send_email_via_resend_sync(
    to_email: str,
    subject: str,
    html_body: str,
    from_email: Optional[str] = None,
    scheduled_at: Optional[str] = None,
) -> None:
    """Synchronous email sending function via Resend to be run in a thread pool.

    Args:
    ----
        to_email (str): Recipient email address
        subject (str): Email subject line
        html_body (str): HTML email body
        from_email (Optional[str]): Sender email (defaults to settings.RESEND_FROM_EMAIL)
        scheduled_at (Optional[str]): ISO 8601 timestamp for scheduled delivery

    """
    resend.api_key = settings.RESEND_API_KEY

    email_data = {
        "from": from_email or settings.RESEND_FROM_EMAIL,
        "to": [to_email],
        "subject": subject,
        "html": html_body,
    }

    if scheduled_at:
        email_data["scheduled_at"] = scheduled_at

    resend.Emails.send(email_data)

```

[backend/airweave/email/services.py](https://github.com/airweave-ai/airweave/blob/1ebe1af2dbfb90f3334410721e69997e4f02b320/backend/airweave/email/services.py#L38-L68) · [More projects using Resend →](https://dashboard.exa.ai/playground/search?q=resend%20GitHub%20projects)

**Quickstart**

```python
import os
import resend

resend.api_key = os.environ["RESEND_API_KEY"]
email = resend.Emails.send({
    "from": "onboarding@resend.dev", "to": ["delivered@resend.dev"],
    "subject": "Hello", "html": "<strong>Hello</strong>",
})

```

From [README.md](https://github.com/resend/resend-python)

### aiosmtplib

[GitHub](https://github.com/cole/aiosmtplib) · [PyPI](https://pypi.org/project/aiosmtplib)

Provides an SMTP client for Python asyncio applications.

- Downloads / mo: 13.0M
- Stars: 438
- Last release: 5.1.3
- License: MIT
- Capabilities: [From the aiosmtplib docs](https://github.com/cole/aiosmtplib)

**Strengths**

- **Provides awaited SMTP operations.** Await connection setup, authentication, and message submission from async application code.
- **Automatically upgrades advertised STARTTLS connections.** Leave automatic upgrades enabled when the server advertises STARTTLS support.

**Watch out for**

- **One connection sends sequentially.** Split email across multiple connections for concurrent submission.
- **Implicit TLS differs from STARTTLS.** Use use_tls only for servers accepting TLS from the connection’s start.

```sh
python -m pip install aiosmtplib
```

**sabuhish/fastapi-mail** (1.0K stars)

[sabuhish/fastapi-mail](https://github.com/sabuhish/fastapi-mail) 

```python
async def _configure_connection(self) -> None:
        try:
            self.session = aiosmtplib.SMTP(
                hostname=self.settings.MAIL_SERVER,
                timeout=self.settings.TIMEOUT,
                port=self.settings.MAIL_PORT,
                use_tls=self.settings.MAIL_SSL_TLS,
                start_tls=self.settings.MAIL_STARTTLS,
                validate_certs=self.settings.VALIDATE_CERTS,
                local_hostname=self.settings.LOCAL_HOSTNAME,
                cert_bundle=self.settings.CERT_BUNDLE,
            )

            if not self.settings.SUPPRESS_SEND:  # for test environ
                await self.session.connect()

                if self.settings.USE_CREDENTIALS:
                    await self.session.login(
                        self.settings.MAIL_USERNAME,
                        self.settings.MAIL_PASSWORD.get_secret_value(),
                    )

        except Exception as error:
            raise ConnectionErrors(
                f"Exception raised {error}, check your credentials or email service configuration"
            )

```

[fastapi_mail/connection.py](https://github.com/sabuhish/fastapi-mail/blob/3842f266f60e6bd069f77b86e78be69ee0baaf52/fastapi_mail/connection.py#L33-L58) · [More projects using aiosmtplib →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20aiosmtplib%20for%20email%20notification%20SMTP%20submission%20and%20message%20delivery&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import asyncio
from email.message import EmailMessage
import aiosmtplib

message = EmailMessage()
message["From"] = "root@localhost"
message["To"] = "somebody@example.com"
message["Subject"] = "Hello World!"
message.set_content("Sent via aiosmtplib")
asyncio.run(aiosmtplib.send(message, hostname="127.0.0.1", port=1025))

```

From [usage.html](https://aiosmtplib.readthedocs.io/en/stable/usage.html)

### Anymail

[GitHub](https://github.com/anymail/django-anymail) · [PyPI](https://pypi.org/project/django-anymail)

Adds Django email backends and webhooks for transactional email providers such as Amazon SES, Mailgun, Postmark, and SendGrid.

- Downloads / mo: 4.0M
- Stars: 1.9K
- Last release: 15.2
- License: BSD-3-Clause
- Capabilities: [From the Anymail docs](https://github.com/anymail/django-anymail)

```sh
python -m pip install django-anymail
```

**mblayman/homeschool** (244 stars)

[mblayman/homeschool](https://github.com/mblayman/homeschool) 

```python
def _generate_magic_link(user_id):
    """Generate magic link and send email."""
    user = User.objects.get(id=user_id)
    login_url = full_url_reverse("sesame-login") + get_query_string(user)
    print(f"Copyable magic login link for {user.email}: {login_url}", flush=True)
    context = {"login_url": login_url}
    text_message = render_to_string("accounts/email/login.txt", context)
    html_message = render_to_string("accounts/email/login.html", context)

    message = AnymailMessage(
        subject="Signin to School Desk",
        body=text_message,
        to=[user.email],
    )
    message.attach_alternative(html_message, "text/html")
    message.send()

```

[homeschool/accounts/tasks.py](https://github.com/mblayman/homeschool/blob/0580b84b86a6593e3e86382f007b8924854136cf/homeschool/accounts/tasks.py#L29-L44) · [More projects using Anymail →](https://dashboard.exa.ai/playground/search?q=django-anymail%20GitHub%20projects)

**Quickstart**

```python
from anymail.message import AnymailMessage

message = AnymailMessage(
    subject="Hello", body="Hello from Anymail",
    from_email="sender@example.com", to=["recipient@example.com"],
)
message.send()

```

From [message.py](https://github.com/anymail/django-anymail/blob/v15.2/anymail/message.py)

### Azure Communication Email

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

Provides a Microsoft Azure client library for Python.

- Downloads / mo: 3.8M
- Stars: 5.6K
- Last release: 1.1.0
- License: MIT
- Capabilities: [From the Azure Communication Email docs](https://github.com/Azure/azure-sdk-for-python)

```sh
python -m pip install azure-communication-email
```

**Azure/azure-cli** (4.7K stars)

[Azure/azure-cli](https://github.com/Azure/azure-cli) 

```python
def send_email(html_content):
    logger.info('Sending email...')
    from azure.communication.email import EmailClient

    client = EmailClient.from_connection_string(EMAIL_KEY);
    content = {
        "subject": "Test results of Azure CLI",
        "html": html_content,
    }

    recipients = ''

    if EMAIL_ADDRESS != '':
        recipients = {
            "to": [
                {
                    "address": EMAIL_ADDRESS
                },
            ]
        }
    elif USER_TARGET.lower() in ['all', ''] \
            and USER_REPO == 'https://github.com/Azure/azure-cli.git' \
            and USER_REPO_EXT == 'https://github.com/Azure/azure-cli-extensions.git' \
            and USER_BRANCH in ['dev', 'live-test'] and USER_BRANCH_EXT in ['main', 'live-test'] \
            and USER_LIVE == '--live' and EMAIL_ADDRESS == '':
        recipients = {
            "to": [
                {
                    "address": "AzPyCLI@microsoft.com"
                },
                {
                    "address": "antcliTest@microsoft.com"
                }
            ]
        }

    if recipients:
        message = {
            "content": content,
            "senderAddress": "DoNotReply@561634e2-1674-4377-9975-10a9197437d7.azurecomm.net",
            "recipients": recipients
        }

        client.begin_send(message)
        logger.info('Finish sending email')
    else:
        logger.info('No recipients, skip sending email')

```

[scripts/live_test/sendemail.py](https://github.com/Azure/azure-cli/blob/a9414b0df27c52c1fed97223e7941759d31889e9/scripts/live_test/sendemail.py#L581-L627) · [More projects using Azure Communication Email →](https://dashboard.exa.ai/playground/search?q=azure-communication-email%20GitHub%20projects)

**Quickstart**

```python
import os
from azure.communication.email import EmailClient

client = EmailClient.from_connection_string(os.environ["COMMUNICATION_CONNECTION_STRING"])
poller = client.begin_send({
    "senderAddress": "sender@contoso.com",
    "content": {"subject": "Hello", "plainText": "Hello from Azure"},
    "recipients": {"to": [{"address": "recipient@example.com"}]},
})

```

From [README.md](https://learn.microsoft.com/en-us/python/api/overview/azure/communication-email-readme?view=azure-python)

### Flask-Mail

[GitHub](https://github.com/pallets-eco/flask-mail) · [PyPI](https://pypi.org/project/flask-mail)

Sends email from Flask applications.

- Downloads / mo: 1.4M
- Stars: 644
- Last release: 0.10.0
- License: BSD-3-Clause
- Capabilities: [From the Flask-Mail docs](https://github.com/pallets-eco/flask-mail)

```sh
python -m pip install flask-mail
```

**hack4impact/flask-base** (3.1K stars)

[hack4impact/flask-base](https://github.com/hack4impact/flask-base) 

```python
def send_email(recipient, subject, template, **kwargs):
    app = create_app(os.getenv('FLASK_CONFIG') or 'default')
    with app.app_context():
        msg = Message(
            app.config['EMAIL_SUBJECT_PREFIX'] + ' ' + subject,
            sender=app.config['EMAIL_SENDER'],
            recipients=[recipient])
        msg.body = render_template(template + '.txt', **kwargs)
        msg.html = render_template(template + '.html', **kwargs)
        mail.send(msg)

```

[app/email.py](https://github.com/hack4impact/flask-base/blob/811fda1cb350ff7881829914c95cb2b10fbe7525/app/email.py#L10-L19) · [More projects using Flask-Mail →](https://dashboard.exa.ai/playground/search?q=flask-mail%20GitHub%20projects)

**Quickstart**

```python
from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)
app.config.update(MAIL_SERVER="localhost", MAIL_PORT=25)
mail = Mail(app)
with app.app_context():
    mail.send(Message("Hello", sender="from@example.com",
                      recipients=["to@example.com"], body="Hello from Flask"))

```

From [index.md](https://flask-mail.readthedocs.io/en/latest/)

## FAQ

### Which Python email library should I use?

[aiosmtplib](#aiosmtplib) suits asyncio applications that send through an SMTP server. [SendGrid](#sendgrid) and [Resend](#resend) suit apps that send through a provider's HTTP API. [Anymail](#django-anymail) suits Django projects that may switch providers.

### How do I send email in Python?

The built-in smtplib module sends a message through any SMTP server. Provider SDKs such as [SendGrid](#sendgrid) and [Resend](#resend) send the same message as an HTTP request to the provider's email API.

### What is smtplib?

smtplib is the SMTP client in the Python standard library. [aiosmtplib](#aiosmtplib) does the same job with asyncio coroutines for connection, authentication, TLS, and sending.

### How do I send email with SendGrid in Python?

Build a message with the [SendGrid](#sendgrid) Mail helper and send it through the SDK client. The client calls the SendGrid email API.

### How do I send email in Django?

[Django](#django) sends multipart email through configurable mail backends. [Anymail](#django-anymail) adds backends and webhooks for transactional email providers such as Mailgun, Postmark, and SendGrid.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python email libraries smtplib aiosmtplib yagmail Flask-Mail fastapi-mail code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
