Skip to content

Instantly share code, notes, and snippets.

@flevour
Created September 15, 2016 13:33
Show Gist options
  • Save flevour/c145c99e5b049bf11877ea4985cbb0fa to your computer and use it in GitHub Desktop.
Save flevour/c145c99e5b049bf11877ea4985cbb0fa to your computer and use it in GitHub Desktop.
Small integration class for `python-emails`
class SendmailViaSES(object):
def sendmail(self, from_addr, to_addrs, msg, **kwargs):
return ses.send_email(
Source=from_addr,
Destination={
'ToAddresses': to_addrs,
},
Message={
'Subject': {
'Data': msg.get_subject(),
},
'Body': {
'Text': {
'Data': msg.text_body,
},
'Html': {
'Data': msg.html_body,
},
}
})
from ses import SendmailViaSES
m = emails.Message(html=templates.get_template("template.html"),
text=templates.from_string("Sample text {{ data }}"),
subject=templates.from_string("Sample subject: {{ data }}"),
mail_from=("", "noreply@example.com"))
response = m.send(render={"data": data},
to=self.recipient_email,
smtp=SendmailViaSES())
@tschm
Copy link

tschm commented Oct 10, 2016

Where is templates. coming from?

@flevour
Copy link
Author

flevour commented Nov 17, 2017

@tschm just saw this: it's a Jinja object, but you can generate the email however you like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment