FLASK-MAILER

A Flask extension for sending email messages.  Includes different mailer
backends for different purposes:

* dummy mailer (useful for tests)
* SMTP mailer (wrapper for SMTP lib)

INSTALLATION

pip install -e git+git://github.com/vitalk/flask-mailer.git#egg=flask-mailer

CONFIGURATION

Use standard Flask config API for set available options:

PREFIX_HOST:            mailer hostname, default 'localhost'
PREFIX_PORT:            mailer port, default 25
PREFIX_USERNAME:        username for backend, default None
PREFIX_PASSWORD:        password for backend, default None
PREFIX_DEFAULT_SENDER:  mailer default sender, default 'webmaster'
PREFIX_BACKEND:         mailer backend, default 'flaskext.mailer.backends.smtp.SMTPMailer'
PREFIX_TESTING:         enable dummy backend for testing, default same as the
                        app.testing

Setup mailer instance:

from flask import Flask
from flaskext.mailer import Mailer

app = Flask(__name__)
mailer = Mailer(app)

Or on deferred way:

mailer = Mailer()

app = Flask(__name__)
mailer.init_app(app)

SENDING EMAILS

If you set 'DEFAULT_SENDER' on config then you don't need to set mail sender
explicitly.

from flaskext.mailer.mail import Email
mail = Email('hi, there', 'awesome message',
             to=['to@example.com', 'you@example.com'],
             from_addr='me@example.com')

If 'from_addr' is two-element tuple, this will be split into name and address:

mail = Email('hi, there', 'awesome message',
             to=['to@example.com', 'you@example.com'],
             from_addr=('me', 'me@example.com'))
assert mail.from_addr == 'me <me@example.com>'

And finally send mail:

from flaskext.mailer import get_mailer
mailer = get_mailer()
mailer.send(mail)

If connection to your mail server fails this will raise an error. To swallow
errors use 'send_quiet' method.

mailer.send_quiet(mail)

It is possible to send mail with previously registered mailer with shortcut:

from flaskext.mailer import send_email
send_email('hi', 'awesome message', 'to@example.com')

TESTING

Setting to your app 'testing' flag automatically enable the dummy mailer
backend or you can manually set 'MAILER_TESTING' to True.  On dummy mailer all
mails on send just append to outbox list:

from flaskext.mailer import get_mailer

mailer = get_mailer()
mail = Email('testing', 'awesome message', 'to@example.com', 'from@example.com')
mailer.send(mail)

assert len(mailer.outbox) == 1
assert mailer.outbox == [mail,]

THANKS

The code based on some existing projects. Special thanks for it authors and
contributors.

* Flask-Mail
* django
* reddit
* plurk

ABOUT ME

My name is Vital Kudzelka <vital.kudzelka@gmail.com>. Fell free to get in touch
and use it as your own.
