Skip to main content
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 notifications

This version
History Node

0.1.3

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
emailqueue-0.1.3-py2-none-any.whl (10.8 kB) Copy SHA256 hash SHA256 Wheel py2 Aug 9, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page