Skip to main content

A mail sending library for keg applications

Project description

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.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

Project details


Download files

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

Source Distribution

Keg-Mail-0.3.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

Keg_Mail-0.3.0-py2.py3-none-any.whl (20.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file Keg-Mail-0.3.0.tar.gz.

File metadata

  • Download URL: Keg-Mail-0.3.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.19

File hashes

Hashes for Keg-Mail-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ca05433e576b2e257f4a205d92544cd47a2e29cae1a601e07d33077551253d31
MD5 dd558a9a8b01c2af968c7f6010adb733
BLAKE2b-256 6f37bfa4ad7cfac8641d4fec74d8549b51b4ab12508cd2bdf4c411716a809563

See more details on using hashes here.

Provenance

File details

Details for the file Keg_Mail-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: Keg_Mail-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.19

File hashes

Hashes for Keg_Mail-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0db1001929aaf3774ee7ac4a1b37bca106789057942891007f35418c4bef1b40
MD5 bee634b124b57d7f8df6c54dfb4263a1
BLAKE2b-256 929e0e2ab510f093641f54a2c425f67d22c0f099d85a2862c93d763ef2aa142b

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page