Envelopes in Flask example

The following code is an example of using Envelopes in Flask apps.

NOTE: Due to Flask’s threaded nature it’s important to wrap envelopes.conn.SMTP object in connection stack.

from envelopes import Envelope, SMTP
import envelopes.connstack
from flask import Flask, jsonify
import os

app = Flask(__name__)
app.config['DEBUG'] = True

conn = SMTP('', 1025)

def app_before_request():

def app_after_request(response):
    return response

@app.route('/mail', methods=['POST'])
def post_mail():
    envelope = Envelope(
        from_addr='%s@localhost' % os.getlogin(),
        to_addr='%s@localhost' % os.getlogin(),
        subject='Envelopes in Flask demo',
        text_body="I'm a helicopter!"

    smtp = envelopes.connstack.get_current_connection()

    return jsonify(dict(status='ok'))

if __name__ == '__main__':

Previous topic

Envelopes in Celery example

Next topic

Envelope class

This Page