https://github.com/level12/keg-mail
A simple mail library for Keg
https://github.com/level12/keg-mail
email flask keg python
Last synced: 23 days ago
JSON representation
A simple mail library for Keg
- Host: GitHub
- URL: https://github.com/level12/keg-mail
- Owner: level12
- License: other
- Created: 2017-03-23T16:52:04.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-06-21T15:15:15.000Z (almost 2 years ago)
- Last Synced: 2025-12-09T17:22:46.535Z (6 months ago)
- Topics: email, flask, keg, python
- Language: Python
- Homepage:
- Size: 3.38 MB
- Stars: 0
- Watchers: 9
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
- Changelog: changelog.rst
- License: LICENSE
Awesome Lists containing this project
README
Keg-Mail
#########
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
=====
.. code::
$ pip install keg-mail
Initialize Keg-Mail in your application
.. code::
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
.. code::
@app_ready.connect
def init_extensions(app):
"""Init custom extensions used by this application"""
mail.init_app(app)
Define email content
.. code::
import keg_mail
hello_world_content = keg_mail.EmailContent(
text='Hello {name}!'
html='
Hello {name}!
'
)
Send the email
.. code::
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
.. code::
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:
.. code::
flask.current_app.mail.send(
msg,
mailgun_opts={
'v:user_name': 'John Doe',
'v:user_id': 100,
},
)