Skip to main content

Keg-Mail is a basic wrapper around Flask-Mail which gives some added support for templates.

It is not finished by any means and in some ways provides little additional benefit over Flask-Mail.

Usage

$ pip install keg-mail

Initialize Keg-Mail in your application

import flask
import keg_mail
from keg.signals import app_ready
from keg import Keg

bp = flask.blueprint('main', __name__)
mail = keg_mail.KegMail()

class App(Keg):
  use_blueprints = [bp]

Initialize the extension with the application

@app_ready.connect
def init_extensions(app):
    """Init custom extensions used by this application"""

    mail.init_app(app)

Define email content

import keg_mail

hello_world_content = keg_mail.EmailContent(
  text='Hello {name}!'
  html='<h1>Hello {name}!</h1>'
)

Send the email

from app import mail
import app.emails as emails
import keg_mail

bp.route('/')
def index():
    mail.send_email(
        'you@something.com',
        keg_mail.Email(
          subject="Hello {name}!",
          content=emails.hello_world_content,
        ).format(name='You")
    )

Test the email

from app import mail

def test_send_mail():
    with mail.record_messages() as outbox:
        resp = app.test_client.get('/')
        assert len(outbox) == 1
        assert outbox[0].subject == "Hello You!"
        assert outbox[0].body == "Hello You!"

Mailgun-specific options

Mailgun supports various options such as tagging, user-defined variables, etc. These can be added via a mailgun_opts dictionary that can be passed to the app’s mail engine’s send method directly:

flask.current_app.mail.send(
    msg,
    mailgun_opts={
        'v:user_name': 'John Doe',
        'v:user_id': 100,
    },
)

Changelog

0.3.1 released 2024-06-21

  • resolve missed signal signature change (52fcc11)

0.3.0 released 2024-06-21

  • automatically pass reply-to header to Mailgun (18fb53f)

  • support flask-mail 0.10.0 changes to signal pattern (3cfe430)

0.2.4 released 2022-11-10

  • allow additional mailgun API options to be sent through send (d35e23d)

  • update CI setup and add python 3.10 (5552cd2)

0.2.3 released 2020-07-22

  • Handle timestamps parsed as decimals in Mailgun event JSON (6a03528)

0.2.2 released 2020-07-22

  • Fix bug in LogStatusWebhook view mixin (8a3ffde)

0.2.1 released 2020-07-22

  • Add support for Mailgun REST API and message status tracking (b3b4428)

0.2.0 released 2020-04-14

0.1.0 - 2017-03-23

  • Initial Release

Metadata

Release files for Keg-Mail 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Keg-Mail 0.3.1
File Size Uploaded
Keg-Mail-0.3.1.tar.gz 16.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Keg-Mail 0.3.1
File Interpreter ABI Platform
Keg_Mail-0.3.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 37.6 kB

Release files / Keg-Mail-0.3.1.tar.gz

Download URL Keg-Mail-0.3.1.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
70c280b5e18f9d79aa1a61e6f90beac51b7d43685fd49697cc91ba122ee995a0
BLAKE2b-256 checksum
How to use checksums
e6e86d106a9e9791a69df8e62efb8bb4a0ff61e924097567acd8e7a14c3bf1d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.19

Release files / Keg_Mail-0.3.1-py2.py3-none-any.whl

Download URL Keg_Mail-0.3.1-py2.py3-none-any.whl
Size 20.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d210608f012a866f3c19dabc333c3638d5ca98ec33e5f9d575c35295d1bdca92
BLAKE2b-256 checksum
How to use checksums
058011c9a0c57f0292b2b3f045cd7b18099c3cf5c4ad139ca543dcda53c53088
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page