uSend Docs
SMTP guides

Django

Point Django's send_mail at usend over SMTP.

Django's mail framework needs only settings changes. Settings used on this page: host smtp.usend.et, port 587 (STARTTLS) or 465 (implicit TLS), username usend, password your API key. Reference: Send with SMTP.

Settings

settings.py
import os

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.usend.et"
EMAIL_PORT = 587
EMAIL_USE_TLS = True            # STARTTLS on 587
EMAIL_HOST_USER = "usend"
EMAIL_HOST_PASSWORD = os.environ["USEND_API_KEY"]
DEFAULT_FROM_EMAIL = "Acme <[email protected]>"
SERVER_EMAIL = "Acme <[email protected]>"   # sender for error emails to ADMINS
EMAIL_TIMEOUT = 30

For implicit TLS use EMAIL_PORT = 465, EMAIL_USE_SSL = True and remove EMAIL_USE_TLS. Set only one of the two; Django refuses both.

DEFAULT_FROM_EMAIL and SERVER_EMAIL must be on a verified domain, or usend refuses the message with 554.

Send

Python
from django.core.mail import EmailMultiAlternatives, send_mail

send_mail("Hello from usend", "It works!", None, ["[email protected]"])

msg = EmailMultiAlternatives("Your invoice", "Attached.", None, ["[email protected]"])
msg.attach_alternative("<p>Attached.</p>", "text/html")
msg.attach_file("invoice.pdf")
msg.send()

Passing None as the sender uses DEFAULT_FROM_EMAIL.

Authentication emails

Django's password reset, and packages such as django-allauth, use the same backend, so they send through usend with no extra work.

Tips

  • Run it under a task queue for bulk mail. Django opens a new SMTP connection per send_mail call unless you share one with get_connection() and send_messages([...]).
  • Locally, switch to django.core.mail.backends.console.EmailBackend so development never sends real mail.
  • Want the email id back, scheduling or tags? Use the API: Send with Django.