Use boto3 to send e-mails with AWS SES, with configuration set support
Project description
Airmailer
Send e-mails with either plain SMTP or AWS SES.
Free software: Apache Software License 2.0
Documentation: https://airmailer.readthedocs.io.
Installation
First, install airmailer:
$ pip install airmailer
Usage: SMTP
from airmailer.backend import SMTPEmailBackend
backend = SMTPEmailBackend(
'smtp.example.com',
username='example',
password='password'
use_tls=True
)
num_sent = backend.send_mail(
'Example Subject',
'Here is my message',
'from@example.com',
['to@destination.com'],
html_message='<p>here is my HTML message</p>'
)
Usage: SES
AWS IAM Policy
Create an IAM Policy like so, and attach it to your EC2 instance profile, ECS task role, etc.:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["ses:SendRawEmail"],
"Resource":"*"
}
]
}
You can invoke the SESEmailBackend either with explicit credentials or you can have it read credentials from the environment.
Explicit credentials
from airmailer.backend import SESEmailBackend
backend = SESEmailBackend(
aws_access_key_id="__THE_ACCESS_KEY_ID__",
aws_secret_access_key="__THE_SECRET_ACCESS_KEY__",
aws_region_name="__THE_REGION_NAME__",
configuration_set_name='example'
)
num_sent = backend.send_mail(
'Example Subject',
'Here is my message',
'from@example.com',
['to@destination.com'],
html_message='<p>here is my HTML message</p>'
)
or
from airmailer.backend import SESEmailBackend
from botocore.config import Config
my_config = Config(
aws_access_key_id="__THE_ACCESS_KEY_ID__",
aws_secret_access_key="__THE_SECRET_ACCESS_KEY__",
region_name="__THE_REGION_NAME__",
)
backend = SESEmailBackend(
aws_config=my_config,
configuration_set_name='example'
)
Credentials from the environment
Configure your credentials in any way named in the Boto3 Configuration Guide.
Then:
from airmailer.backend import SESEmailBackend
backend = SESEmailBackend(configuration_set_name='example')
num_sent = backend.send_mail(
'Example Subject',
'Here is my message',
'from@example.com',
['to@destination.com'],
html_message='<p>here is my HTML message</p>'
)
History
0.1.0 (2021-11-30)
First release on PyPI.
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
airmailer-0.1.1.tar.gz
(20.2 kB
view hashes)
Built Distribution
Close
Hashes for airmailer-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48b23b376179efafbb9c9f5a4db2d7830f6c4066d940644eb0a13724a94822b1 |
|
MD5 | 703b76b752945d4df6f882c0572711a5 |
|
BLAKE2b-256 | 7a0b452926eb98a3ce40b34395cfbc128b0bef2d89d7e62db763adcd47dd8681 |