Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Non-blocking Email Queue for Tornado Web Framework

Project Description

Tornado Email Queue is a non-blocking email queue for Python Tornado. This library uses MongoDB to store the queue data.

Installation

pip install emailqueue

Dependencies

Tornado Email Queue requires the environments officially supported by Tornado and MongoDB.

Requirements:

  • MongoDB
  • Python 2.7
  • tornado >= 4.2.1
  • motor >= 0.4.1
  • bson >= 0.4.0
  • futures >= 3.0.3

Examples

Here is a simple example of a Tornado web app with an email queue instance:

from tornado import httpserver, ioloop, web
from tornado.options import options
from emailqueue.queues import MongoDbEmailQueue

smtp_user = 'sender@gmail.com'
smtp_password = ''
recipient_addrs = 'recipient@hotmail.com'

# Create the email queue.
email_queue = MongoDbEmailQueue(
    smtp_host='smtp.gmail.com',
    smtp_port=587,
    smtp_user=smtp_user,
    smtp_password=smtp_password,
    mongodb_uri='mongodb://localhost:27017',
    mongodb_collection='email_queue',
    mongodb_database='sample_db',
    queue_maxsize=0
)


class MainHandler(web.RequestHandler):

    def get(self):

        # Put new email in the queue for processing
        # by the mailer worker at the scheduled time.
        email_queue.sendmail(
            subject='Hello World Sample',
            from_addr=smtp_user,
            to_addrs=recipient_addrs,
            text='Greetings from Tornado Email Queue.',
            mime_type='plain',
            charset='utf-8',
            scheduled_hours_from_now=0
        )

        # Render a tornado html template and put it in the queue
        # for processing by the mailer worker at the scheduled time.
        email_queue.sendmail_from_template(
            subject='Tornado Templates Sample',
            from_addr=smtp_user,
            to_addrs=recipient_addrs,
            template_path='templates/email.html',
            params={'link': 'http://ricardoyorky.github.io/emailqueue/'},
            mime_type='html',
            charset='utf-8',
            scheduled_hours_from_now=0
        )

        self.write("Mail sent")


def main():
    options.parse_command_line()
    application = web.Application([
        (r"/", MainHandler),
    ])

    # Add email queue callback to IOLoop
    ioloop.IOLoop.current().add_callback(email_queue.worker)

    http_server = httpserver.HTTPServer(application)
    http_server.listen(8888)
    ioloop.IOLoop.current().start()


if __name__ == "__main__":
    main()
Release History

Release History

This version
History Node

0.1.3

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
emailqueue-0.1.3-py2-none-any.whl (10.8 kB) Copy SHA256 Checksum SHA256 py2 Wheel Aug 9, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting