Skip to content

Instantly share code, notes, and snippets.

@axolx
Last active December 31, 2015 23:59
Show Gist options
  • Save axolx/8063895 to your computer and use it in GitHub Desktop.
Save axolx/8063895 to your computer and use it in GitHub Desktop.
Sendmail `mail` with AWS SES
#! /usr/bin/env python
"""
A very basic script that emulates Sendmail's `mail` command, sending emails
with [aws-cli](https://github.com/aws/aws-cli). It replicates the minimum
amount of functionality for delivery [Munin notifications](
http://munin-monitoring.org/wiki/HowToContact) (e.g. `contact.email.command
ses_mail -s "Munin-notification for ${var:group} :: ${var:host}" your@email
.address.here`
).
"""
import sys, argparse, json
from subprocess import call
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--subject', help='Email subject')
parser.add_argument("to")
args = parser.parse_args()
message = {
'Body': {
'Text': {
'Data': ''.join(sys.stdin.readlines()),
'Charset': 'UTF-8',
}
}
}
call([
"aws",
"--region",
"us-east-1",
"ses",
"send-email",
"--from",
"noreply@ombuweb.com",
"--to",
args.to,
"--subject",
args.subject or 'Empty subject',
"--message",
json.dumps(message),
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment