ZeptoMail for Django facilitates email sending from Django applications using ZeptoMail APIs.
Project description
Email sending using Zoho ZeptoMail in Django
Django ZeptoMail
ZeptoMail for Django facilitates email sending from Django applications using ZeptoMail APIs.
Installation
pip install django-zoho-zeptomail
Settings configuration
Add the following parameters in the application settings.
EMAIL_BACKEND = 'zoho_zeptomail.backend.zeptomail_backend.ZohoZeptoMailEmailBackend'
DEFAULT_FROM_EMAIL = 'rebecca@zylker.com' #The default FROM address that will be used for all emails. Optional parameter.
ZOHO_ZEPTOMAIL_API_KEY_TOKEN = 'Send Mail Token' #Send Mail Token generated from the ZeptoMail account.
ZOHO_ZEPTOMAIL_HOSTED_REGION = 'zeptomail.zoho.com' #Region where the account is hosted. Optional for US. Mandatory for other regions.
Email-sending
Text-only emails
- To send a plain text message using Django's send_mail function
from django.core.mail import send_mail
send_mail(
subject='Hello!',
message='This is an acknowledgement for your action on our website',
from_email='rebecca@zylker.com',
recipient_list=['sam@zylker.com']
)
- To add other recipients (CC, BCC) using EmailMessage class
from django.core.mail.message import EmailMessage
email_message = EmailMessage(
subject='Hello!',
body='This is an acknowledgement for your action on our website',
from_email='rebecca@zylker.com',
to=['sam@zylker.com'],
bcc=['john@zylker.com'], # Optional
cc=['george@zylker.com'], # Optional
reply_to=['samuel@zylker.com'] # Optional
)
email_message.send()
Text + HTML emails
- To send text and HTML emails,
from django.core.mail import send_mail
send_mail(
subject='Hello!',
message='This is an acknowledgement for your action on our website',
from_email='rebecca@zylker.com',
recipient_list=['sam@zylker.com'],
html_message='This is an acknowledgement for your action on our website'
)
- To add other recipients (CC, BCC) using EmailMultiAlternatives class
from django.core.mail.message import EmailMultiAlternatives
email_message = EmailMultiAlternatives(
subject='Hello!',
body='This is an acknowledgement for your action on our website',
from_email='rebecca@zylker.com',
to=['sam@zylker.com'],
bcc=['john@zylker.com'], # Optional
cc=['george@zylker.com'], # Optional
reply_to=['samuel@zylker.com'] # Optional
)
email_message.attach_alternative(
'This is an acknowledgement for your action on our website',
'text/html'
)
email_message.send()
Using attachments
You can add attachments while using EmailMessage as well as EmailMultiAlternatives classes. This can be achieved in three ways using different methods:
- Using file path
from django.core.mail.message import EmailMessage
email_message = EmailMessage(
subject='Hello!',
body='This is an acknowledgement for your action on our website',
from_email='rebecca@zylker.com',
to=['sam@zylker.com']
)
email_message.attach_file('/example/attachment.txt')
email_message.attach_file('/example/attachment.jpg')
email_message.send()
- Using a filename and file content
from django.core.mail.message import EmailMessage
email_message = EmailMessage(
subject='Hello!',
body='This is an acknowledgement for your action on our website',
from_email='rebecca@zylker.com',
to=['sam@zylker.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()
- Using MIMEBase instance
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
from django.core.mail.message import EmailMessage
email_message = EmailMessage(
subject='Hello!',
body='This is an acknowledgement for your action on our website',
from_email='rebecca@zylker.com',
to=['sam@zylker.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/
- Zoho ZeptoMail : https://www.zoho.com/zeptomail/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_zoho_zeptomail-0.0.3.tar.gz.
File metadata
- Download URL: django_zoho_zeptomail-0.0.3.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4b703bd8c954f430c0405a9bb3829c592e227398d980211158c89f157e8560f
|
|
| MD5 |
cbc0d1dc0d9ff15796bff0c856bf51ab
|
|
| BLAKE2b-256 |
dbc798d2719d572f57acf1063b2b0acfcfd3532ec733c21eb14aaf0383762474
|
File details
Details for the file django_zoho_zeptomail-0.0.3-py3-none-any.whl.
File metadata
- Download URL: django_zoho_zeptomail-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5172137cb6a923d4448831fc0cfe1125729f9148775263bb4c3e1b6e97bb1c5c
|
|
| MD5 |
c44acf2015a491c4c4091511131c2a1f
|
|
| BLAKE2b-256 |
97d2a48d3f5fcc5f419c78a61c568404e2d5a30138f415ad8574313f138aaac7
|