Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
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
SendGrid has the most monthly downloads among the dedicated email libraries in this comparison, at 24.2M.
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])
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 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"))
aiosmtplib suits asyncio applications that send through an SMTP server. SendGrid and Resend suit apps that send through a provider's HTTP API. Anymail suits Django projects that may switch providers.
The built-in smtplib module sends a message through any SMTP server. Provider SDKs such as SendGrid and Resend send the same message as an HTTP request to the provider's email API.
smtplib is the SMTP client in the Python standard library. aiosmtplib does the same job with asyncio coroutines for connection, authentication, TLS, and sending.
Build a message with the SendGrid Mail helper and send it through the SDK client. The client calls the SendGrid email API.
Django sends multipart email through configurable mail backends. Anymail adds backends and webhooks for transactional email providers such as Mailgun, Postmark, and SendGrid.
For coding agents
Found your email library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.