Package: django-mailersend
Django MailerSendDjango MailerSend makes it easier to send emails in Django apps using the
MailerSend API. Uses the official MailerSend Python SDK internally.IndexInstallationConfigurationUsageText Only EmailsText + HTML EmailsAttachmentsInstallationpip install django-mailersendConfigurationAdd the following to your Django settings:EMAIL_BACKEND = 'django_mailersend.backend.MailerSendEmailBackend'
MAILERSEND_API_KEY = 'Your API key'UsageText Only EmailsSend aText Onlyemail using Django'ssend_mailfunction:fromdjango.core.mailimportsend_mailsend_mail(subject='Hello world!',message='Sent using the Django MailerSend Email Backend!',from_email='sender@example.com',recipient_list=['receiver@example.com'])Send aText Onlyemail using Django'sEmailMessageclass for more options:fromdjango.core.mail.messageimportEmailMessageemail_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'],# Optionalcc=['cc@example.com'],# Optionalreply_to=['reply-to@example.com']# Optional)email_message.send()Text + HTML EmailsSend aText + HTMLemail using Django'ssend_mailfunction:fromdjango.core.mailimportsend_mailsend_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 aText + HTMLemail using Django'sEmailMultiAlternativesclass for more
options:fromdjango.core.mail.messageimportEmailMultiAlternativesemail_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'],# Optionalcc=['cc@example.com'],# Optionalreply_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()AttachmentsSending attachments is supported when using Django'sEmailMessageorEmailMultiAlternativesclasses. There are several ways of doing this:Send an attachment by providing the filepathto theattach_filemethod:fromdjango.core.mail.messageimportEmailMessageemail_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 afilenameand the filecontentto theattachmethod:fromdjango.core.mail.messageimportEmailMessageemail_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')withopen('/example/attachment.txt','r')asfile:email_message.attach('attachment.txt',file.read())# Binary file (Read mode 'rb')withopen('/example/attachment.jpg','rb')asfile:email_message.attach('attachment.jpg',file.read())email_message.send()Send an attachment by providing aMIMEBaseinstance to theattachmethod:fromemail.mime.imageimportMIMEImagefromemail.mime.textimportMIMETextfromdjango.core.mail.messageimportEmailMessageemail_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')withopen('/example/attachment.txt','r')asfile: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')withopen('/example/attachment.jpg','rb')asfile:mime_image=MIMEImage(file.read())mime_image.add_header('Content-Disposition','inline; filename=attachment.jpg')email_message.attach(mime_image)email_message.send()ResourcesDjango:https://www.djangoproject.com/MailerSend:https://www.mailersend.com/MailerSend Python SDK:https://github.com/mailersend/mailersend-python