Skip to main content

A simple module to send email via AWS SES

Project description

SES Mailer 3

This is a fork of a fork, since the other projects haven't been updated. This version uses boto3 rather than the out-of-date boto module.

A simple module to send email via AWS SES

You can use it as standalone or with Flask

Requirements:

  • AWS Credentials
  • boto3
  • Jinja

Install

pip install ses-mailer-3

Usage

Setup

from ses_mailer import Mail

mail = Mail(aws_access_key_id="####",
            aws_secret_access_key="####",
            region="us-east-1",
            sender="me@myemail.com",
            reply_to="me@email.com",
            template="./email-templates")

Alternatively, if you want to use botocore's default credentials lookup scheme, you can pass aws_boto_auth_lookup=True instead of providing keys.

Send Basic Email

mail.send(to="you@email.com",
          subject="My Email subject",
          body="My message body")

Send Template Email

mail.send_template(template="welcome.txt", 
                   to="you@email.com", 
                   name="Ricky Roze", 
                   user_id=12739)

##API

Mail._init_

- aws_access_key_id
- aws_secret_access_key
- sender
- reply_to
- template

Mail.send

- to
- subject
- body
- reply_to

Mail.send_template

- template
- to
- reply_to
- **context	

Initiate with Flask

from flask import Flask
from ses_mailer import Mail

app = Flask(__name__)

mail = Mail()
mail.init_app(app)

Templates

You can use pre-made templates to send email

The template must be a Jinja template, containing at least the following blocks:

- subject
- body

welcome.txt

{% block subject %}
    Welcome {{name}} to our site 
{% endblock %}

{% block body %}
    Dear {{name}} this is the content of the message 

    Thank you very much for your visiting us
{% endblock %}

File Templates:

Place you template files inside of a directory, let's say: email-templates

Inside of email-templates we have the following files:

/email-templates
    |
    |_ welcome.txt
    |
    |_ lost-password.txt


mail = Mail(aws_access_key_id="####",
             aws_secret_access_key="####",
             sender="me@myemail.com",
             reply_to="me@email.com",
             template="./email-templates")

Dictionary based templates

If you don't want to create files, you can dictionary based templates

templates = {
    "welcome.txt": """
        {% block subject %}I'm subject{% endblock %}
        {% block body %}How are you {{name}}?{% endblock %}
    """,
    "lost-password.txt": """
        {% block subject %}Lost Password{% endblock %}
        {% block body %}Hello {{ name }}. 
        Here's your new password: {{ new_password }} 
        {% endblock %}
    """,    
}

mail = Mail(aws_access_key_id="####",
             aws_secret_access_key="####",
             sender="me@myemail.com",
             reply_to="me@email.com",
             template=templates)

To send the email for either files or dictionary based templates:

new_password = "mynewpassword"
mail.send_template("lost-password.txt", to="x@y.com", name="Lolo", new_password=new_password)

Config For Flask

SES-Mailer is configured through the standard Flask config API. These are the available options:

SES_AWS_ACCESS_KEY : Your AWS access key id

SES_AWS_SECRET_KEY: Your AWS secred key

SES_REGION: AWS region of the SES

SES_AWS_BOTO_LOOKUP: Flag asking to use Boto's default credentials lookup scheme

SES_SENDER: The sender email address as string.

SES_REPLY_TO: The reply to address

SES_TEMPLATE: (mixed) directory or dict of template to use as template

SES_TEMPLATE_CONTEXT: A dict of template data to be passed by default

SES_AWS_ACCESS_KEY = ""
SES_AWS_SECRET_KEY = ""
SES_REGION = ""
SES_AWS_BOTO_LOOKUP = False
SES_SENDER = ""
SES_REPLY_TO = ""
SES_TEMPLATE = None
SES_TEMPLATE_CONTEXT = {}

(c) 2015 Mardix

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

SES-Mailer-3-0.15.2.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SES_Mailer_3-0.15.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file SES-Mailer-3-0.15.2.tar.gz.

File metadata

  • Download URL: SES-Mailer-3-0.15.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1

File hashes

Hashes for SES-Mailer-3-0.15.2.tar.gz
Algorithm Hash digest
SHA256 74324c6e9c8a081f631bfac70cf9f569c9ba30e2a7a8a7cc66d7581713d9545e
MD5 74a7a6051e2cda20a37a5722f38bd946
BLAKE2b-256 61c0d65be91a8dfeef88f561288e928bd20b651c95e54f5de24f630848a1b6a4

See more details on using hashes here.

File details

Details for the file SES_Mailer_3-0.15.2-py3-none-any.whl.

File metadata

  • Download URL: SES_Mailer_3-0.15.2-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1

File hashes

Hashes for SES_Mailer_3-0.15.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9daa4a074f2865e833758000ba17fe57f7e68ebdb9ef61335425fc3b38b37f53
MD5 bc16674d74fd66860f3f1b7ba6881927
BLAKE2b-256 3b23ef0d2fd6407c9eaa986eeb7040d86f2c5206bd6c0a11d9d4a44957a07d44

See more details on using hashes here.

Supported by

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