Django MailerSend
Django MailerSend makes it easier to send emails in Django apps using the MailerSend API. Uses the official MailerSend Python SDK internally.
Index
- Installation
- Configuration
- Usage
- Text Only Emails
- Text + HTML Emails
- Attachments
Installation
pip install django-mailersend
Configuration
Add the following to your Django settings:
EMAIL_BACKEND = 'django_mailersend.backend.MailerSendEmailBackend'
MAILERSEND_API_KEY = 'Your API key'
Usage
Text Only Emails
- Send a Text Only email using Django's
send_mailfunction:
from django.core.mail import send_mail
send_mail(
subject='Hello world!',
message='Sent using the Django MailerSend Email Backend!',
from_email='sender@example.com',
recipient_list=['receiver@example.com']
)
- Send a Text Only email using Django's
EmailMessageclass for more options:
from django.core.mail.message import EmailMessage
email_message = EmailMessage(
subject='Hello world!',
body='Sent using the Django MailerSend Email Backend!',
from_email='sender@example.com',
to=['receiver@example.com'],
bcc=['bcc@example.com'], # Optional
cc=['cc@example.com'], # Optional
reply_to=['reply-to@example.com'] # Optional
)
email_message.send()
Text + HTML Emails
- Send a Text + HTML email using Django's
send_mailfunction:
from django.core.mail import send_mail
send_mail(
subject='Hello world!',
message='Sent using the Django MailerSend Email Backend!',
from_email='sender@example.com',
recipient_list=['receiver@example.com'],
html_message='<p>Sent using <strong>Django MailerSend Email Backend</strong>!</p>'
)
- Send a Text + HTML email using Django's
EmailMultiAlternativesclass for more options:
from django.core.mail.message import EmailMultiAlternatives
email_message = EmailMultiAlternatives(
subject='Hello world!',
body='Sent using Django MailerSend Email Backend!',
from_email='sender@example.com',
to=['receiver@example.com'],
bcc=['bcc@example.com'], # Optional
cc=['cc@example.com'], # Optional
reply_to=['reply-to@example.com'] # Optional
)
email_message.attach_alternative(
'<p>Sent using <strong>Django MailerSend Email Backend</strong>!</p>',
'text/html'
)
email_message.send()
Attachments
Sending attachments is supported when using Django's EmailMessage or
EmailMultiAlternatives classes. There are several ways of doing this:
- Send an attachment by providing the file
pathto theattach_filemethod:
from django.core.mail.message import EmailMessage
email_message = EmailMessage(
subject='Hello world!',
body='Sent using the Django MailerSend Email Backend!',
from_email='sender@example.com',
to=['receiver@example.com']
)
email_message.attach_file('/example/attachment.txt')
email_message.attach_file('/example/attachment.jpg')
email_message.send()
- Send an attachment by providing a
filenameand the filecontentto theattachmethod:
from django.core.mail.message import EmailMessage
email_message = EmailMessage(
subject='Hello world!',
body='Sent using the Django MailerSend Email Backend!',
from_email='sender@example.com',
to=['receiver@example.com']
)
# Text file (Read mode 'r')
with open('/example/attachment.txt', 'r') as file:
email_message.attach('attachment.txt', file.read())
# Binary file (Read mode 'rb')
with open('/example/attachment.jpg', 'rb') as file:
email_message.attach('attachment.jpg', file.read())
email_message.send()
- Send an attachment by providing a
MIMEBaseinstance to theattachmethod:
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
from django.core.mail.message import EmailMessage
email_message = EmailMessage(
subject='Hello world!',
body='Sent using the Django MailerSend Email Backend!',
from_email='sender@example.com',
to=['receiver@example.com']
)
# Text file (Read mode 'r')
with open('/example/attachment.txt', 'r') as file:
mime_text = MIMEText(file.read())
mime_text.add_header(
'Content-Disposition', 'attachment; filename=attachment.txt')
email_message.attach(mime_text)
# Binary file (Read mode 'rb')
with open('/example/attachment.jpg', 'rb') as file:
mime_image = MIMEImage(file.read())
mime_image.add_header(
'Content-Disposition', 'inline; filename=attachment.jpg')
email_message.attach(mime_image)
email_message.send()
Resources
- Django: https://www.djangoproject.com/
- MailerSend: https://www.mailersend.com/
- MailerSend Python SDK: https://github.com/mailersend/mailersend-python
Metadata
Release files for django-mailersend 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_mailersend-0.2.1.tar.gz | 5.1 kB | Without provenance | Details for django_mailersend-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_mailersend-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for django_mailersend-0.2.1-py3-none-any.whl |
Total release size: 11.1 kB
Release files / django_mailersend-0.2.1.tar.gz
| Download URL | django_mailersend-0.2.1.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3c258a219aa48b651f3a6688a0c9675a80f808fea9bf62edf866d226c4efed7
|
|
BLAKE2b-256 checksum How to use checksums |
ef41c0f6437acf426620128e4c6e84e1238950d9a8c1024a2791783617df76aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / django_mailersend-0.2.1-py3-none-any.whl
| Download URL | django_mailersend-0.2.1-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84bb191257f9e665d84424ef1b73db1c6051d4fbd817d6f24b9573e070eda91e
|
|
BLAKE2b-256 checksum How to use checksums |
2b1a573280a7d7a0197ddb22d18c19f90712d61e71c3462063572580775117a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for django-mailersend 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.