Django Mail Queue Documentation

Similar documents
Tailor Documentation. Release 0.1. Derek Stegelman, Garrett Pennington, and Jon Faustman

git-pr Release dev2+ng5b0396a

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

X Generic Event Extension. Peter Hutterer

mp3fm Documentation Release Akshit Agarwal

PyCon APAC 2014 Documentation

retask Documentation Release 1.0 Kushal Das

utidylib Documentation Release 0.4

inflection Documentation

Dellve CuDNN Documentation

Sensor-fusion Demo Documentation

sensor-documentation Documentation

BME280 Documentation. Release Richard Hull

agate-sql Documentation

deepatari Documentation

Feed Cache for Umbraco Version 2.0

dublincore Documentation

XStatic Documentation

Elegans Documentation

twstock Documentation

disspcap Documentation

puppet-diamond Documentation

MCAFEE THREAT INTELLIGENCE EXCHANGE RESILIENT THREAT SERVICE INTEGRATION GUIDE V1.0

abstar Documentation Release Bryan Briney

invenio-formatter Documentation

aiounittest Documentation

jumpssh Documentation

Instagram PHP Documentation

Spotter Documentation Version 0.5, Released 4/12/2010

NDIS Implementation Guide

Testworks User Guide. Release 1.0. Dylan Hackers

Piexif Documentation. Release 1.0.X. hmatoba

Open Source Used In Cisco Configuration Professional for Catalyst 1.0

CuteFlow-V4 Documentation

delegator Documentation

Piexif Documentation. Release 1.0.X. hmatoba

django-helpdesk Documentation

Firebase PHP SDK. Release

josync Documentation Release 1.0 Joel Goop and Jonas Einarsson

Guest Book. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

XEP-0087: Stream Initiation

SopaJS JavaScript library package

TWO-FACTOR AUTHENTICATION Version 1.1.0

PHP-FCM Documentation

OPi.GPIO Documentation

SW MAPS TEMPLATE BUILDER. User s Manual

KEMP Driver for Red Hat OpenStack. KEMP LBaaS Red Hat OpenStack Driver. Installation Guide

pydocstyle Documentation

Daedalus Documentation

Statsd Metrics Documentation

Asthma Eliminator MicroMedic Competition Entry

Inptools Manual. Steffen Macke

XEP-0099: IQ Query Action Protocol

Migration Tool. Migration Tool (Beta) Technical Note

MatPlotTheme Documentation

Industries Package. TARMS Inc.

Imagination Documentation

clipbit Release 0.1 David Fraser

Moodle. Moodle. Deployment Guide

HTNG Web Services Product Specification. Version 2011A

LoadMaster VMware Horizon (with View) 6. Deployment Guide

VMware vcenter Log Insight Manager. Deployment Guide

XTEST Extension Library

Splunk. Splunk. Deployment Guide

Django MFA Documentation

Colgate, WI

ExaFMM. Fast multipole method software aiming for exascale systems. User's Manual. Rio Yokota, L. A. Barba. November Revision 1

RTI Connext DDS Core Libraries

mqtt-broker Documentation

webbot Documentation Release Natesh M Bhat

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Packet Trace Guide. Packet Trace Guide. Technical Note

HTNG Web Services Product Specification. Version 2014A

Upgrading BankLink Books

Imagination Documentation

Black Mamba Documentation

docxtemplater Documentation

SagePay payment gateway package for django-oscar Documentation

NTLM NTLM. Feature Description

LANDISVIEW Beta v1.0-user Guide

XTEST Extension Protocol

MEAS HTU21D PERIPHERAL MODULE

Adobe Connect. Adobe Connect. Deployment Guide

Epic. Epic Systems. Deployment Guide

Transparency & Consent Framework

MEAS TEMPERATURE SYSTEM SENSOR (TSYS01) XPLAINED PRO BOARD

XEP-0044: Full Namespace Support for XML Streams

XEP-0052: File Transfer

ClassPad Manager Subscription

RSA Two Factor Authentication

Django IPRestrict Documentation

Hyper-V - Windows 2012 and 8. Virtual LoadMaster for Microsoft Hyper-V on Windows Server 2012, 2012 R2 and Windows 8. Installation Guide

XEP-0363: HTTP File Upload

User Guide. Calibrated Software, Inc.

XEP-0399: Client Key Support

ProFont began life as a better version of Monaco 9 which is especially good for programmers. It was created circa 1987 by Andrew Welch.

The XIM Transport Specification

Additional License Authorizations for HPE OneView for Microsoft Azure Log Analytics

youtube-dl-api-server Release 0.3

XEP-0140: Shared Groups

Transcription:

Django Mail Queue Documentation Release 3.1.0 Derek Stegelman Jan 27, 2018

Contents 1 Quick Start Guide 3 1.1 Requirements............................................... 3 1.2 Installation................................................ 3 1.3 Setup................................................... 3 1.4 Synchronously.............................................. 4 1.5 Celery.................................................. 4 1.6 Management Command/URL...................................... 4 1.7 Misc Settings............................................... 5 2 Usage 7 2.1 To Send an Email............................................. 7 2.2 Attaching Files.............................................. 7 2.3 Adding a Reply To header........................................ 8 2.4 Sending to Multiple Recipients..................................... 8 2.5 Using the Management Command.................................... 8 3 Management Commands 9 3.1 Send Queued messages.......................................... 9 3.2 Clear Sent messages........................................... 9 4 License 11 5 Contributing 13 6 Indices and tables 15 i

ii

Django Mail Queue Documentation, Release 3.1.0 Mail Queue is a new way to send and keep track of email in your Django application. Mail queue stores each email you send and records success/failure. You can requeue up un-sent mail and review the mail generated by your app. Contents: Contents 1

Django Mail Queue Documentation, Release 3.1.0 2 Contents

CHAPTER 1 Quick Start Guide As of 2.0 Django Mail Queue is now Python 3 compatible! 1.1 Requirements Django Mail Queue requires: python 2.7 or greater django 1.8 or greater Django Mail Queue is tested against Python 2.7, 3.x and Django 1.8 and 1.9. If using Celery, you ll need celery 3 or greater. 1.2 Installation Using pip: pip install django-mail-queue Go to https://github.com/dstegelman/django-mail-queue if you need to download a package or clone the repo. 1.3 Setup Open settings.py and add mailqueue to your INSTALLED_APPS: INSTALLED_APPS = ( 'mailqueue', ) 3

Django Mail Queue Documentation, Release 3.1.0 Mailqueue can be configured a few different ways: Configured to send mail synchronously in the web request. Configured to send mail asynchronously through Celery. Configured to queue up and send mail in bulk through a management command. Confgiured to queue up and send mail in bulk through a hitting a URL. (pending deprecation) 1.4 Synchronously This is the default setting for mailqueue. You do not need to set any additional settings for this option. 1.5 Celery Celery is disabled by default, you can turn it on the use of Celery and send emails in real time using MAILQUEUE_CELERY in settings: MAILQUEUE_CELERY = True Instead of using the cron job the celery task worker will attempt to send email when it s saved. The cron job will clean up any emails that get lost. 1.6 Management Command/URL First, in order to queue up the mail and not send on save(), you ll need to set the queue up: MAILQUEUE_QUEUE_UP = True A cron job can be set up to work one of two ways: using a management command or an HTTP request. Both methods run the mail queue which grabs emails and sends them. To decrease load, it only tries to send 30 emails at a time. This number can be changed by using MAILQUEUE_LIMIT in settings: MAILQUEUE_LIMIT = 50 Using the management command: python manage.py send_queued_messages You can also override MAILQUEUE_LIMIT by using the --limit or -l option: python manage.py send_queued_messages --limit=10 HTTP request: urlpatterns = patterns('', (r'^mail-queue/', include('mailqueue.urls')), ) If you re running cron from another machine or can t run python directly, you can add the above to urls.py and use a utility like curl to hit /mail-queue/. 4 Chapter 1. Quick Start Guide

Django Mail Queue Documentation, Release 3.1.0 1.7 Misc Settings You can force mail queue to use default file system storage with MEDIA_ROOT as the storage folder. You may want to do this because by default mail queue will use your default file storage, and attachments are known to not work against various storages such as S3 Boto. To force Django s File System storage: MAILQUEUE_STORAGE = True To change the Attachment dir: MAILQUEUE_ATTACHMENT_DIR = 'mailqueue-attachments' 1.7. Misc Settings 5

Django Mail Queue Documentation, Release 3.1.0 6 Chapter 1. Quick Start Guide

CHAPTER 2 Usage 2.1 To Send an Email Create a new MailerMessage() object: from mailqueue.models import MailerMessage new_message = MailerMessage() new_message.subject = "My Subject" new_message.to_address = "someone@example.com" new_message.cc_address = "carboncopy@yo.com" new_message.bcc_address = "myblindcarboncopy@yo.com" new_message.from_address = "hello@example.com" new_message.content = "Mail content" new_message.html_content = "<h1>mail Content</h1>" new_message.app = "Name of your App that is sending the email." new_message.save() When save is called, Django will immediately try to send the email. Should it fail, it will be marked as unsent, and wait for the next time the job is called. Of course, the BCC address is optional, as well as html content. 2.2 Attaching Files File attachments can be added to the e-mail with MailerMessage s add_attachment method: from mailqueue.models import MailerMessage from django.core.files import File message = MailerMessage(to_address="foo@mail.com", from_address="bar@mail.com") photo_one = File(open("Poznan_square.jpg", "rb")) message.add_attachment(photo_one) 7

Django Mail Queue Documentation, Release 3.1.0 #...you can add more than one file attachment photo_two = File(open("Poznan_Malta-lake.jpg", "rb")) message.add_attachment(photo_two) message.save() 2.3 Adding a Reply To header You can add a reply to header to your emails be setting: from mailqueue.models import MailerMessage new_message = MailerMessage() new_message.reply_to = 'reply@myawesomeaddress.com' 2.4 Sending to Multiple Recipients To include more than one CC/BCC in your email, just separate the addresses with a comma: message.cc_address = "one@mail.com, two@mail.com, three@mail.com" message.bcc_address = "one@mail.com, two@mail.com, three@mail.com" As of version 2.2.0 multiple recipients may be included in the to_address field as well: message.to_address = "one@mail.com, two@mail.com, three@mail.com" 2.5 Using the Management Command You can use the management command to send email: python manage.py send_queued_messages --limit=20 8 Chapter 2. Usage

CHAPTER 3 Management Commands 3.1 Send Queued messages You can use this management command to send email if you do not setup a cron job or use celery. You can specify a limit on the amount of emails you want to attempt to send at one time.: python manage.py send_queued_messages 20 3.2 Clear Sent messages You can use a management command to clear out successfully sent emails from the database:./manage.py clear_sent_messages 9

Django Mail Queue Documentation, Release 3.1.0 10 Chapter 3. Management Commands

CHAPTER 4 License Copyright (c) 2011-2017 Derek Stegelman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software ), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PAR- TICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT- WARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11

Django Mail Queue Documentation, Release 3.1.0 12 Chapter 4. License

CHAPTER 5 Contributing Mail Queue is hosted on github at https://github.com/dstegelman/django-mail-queue Contributions are more than welcome! 13

Django Mail Queue Documentation, Release 3.1.0 14 Chapter 5. Contributing

CHAPTER 6 Indices and tables genindex modindex search 15