Skip to content

AnswerDotAI/markdown_merge

Repository files navigation

MarkdownMerge

Send templated emails in markdown.

Install

pip install markdown_merge

How to use

Provide your SMTP server settings, e.g. for fastmail

cfg = dict(EMAIL_HOST='smtp.fastmail.com', EMAIL_PORT=465,
    EMAIL_HOST_USER='XXX@fastmail.com', EMAIL_HOST_PASSWORD='XXX', EMAIL_USE_SSL=True)

Alternately you can put your server settings in mail_settings.py. There's an example settings file in the repo.

Provide your email details

from_addr = get_addr('XXX@fastmail.com', 'Jeremy Howard')
to_addrs = [get_addr('douglas@example.com', 'Douglas Adams'),
            get_addr('cleese@example.com', 'John Cleese')]
inserts  = [{'special': "Thanks for all the fish."},
            {'special': "That was a silly walk."}]

msg = """## Hello there!

Here is your special message: *{special}*"""
ml = MarkdownMerge(to_addrs, from_addr, 'A message', msg=msg, inserts=inserts)

Optionally, enable test mode to just print the messages, instead of sending them.

ml.set_test(True)

Send your messages

ml.send_msgs()

Credits

All the hard work is done by Django mail, python-markdown, and python. So thanks to the authors of those projects!