Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anand B Pillai
committed
Sep 9, 2016
1 parent
48ea1ef
commit 0ffaaf9
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import boto | ||
from email.mime.application import MIMEApplication | ||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
|
||
def send_ses(fromaddr, | ||
subject, | ||
body, | ||
recipient, | ||
attachment=None, | ||
filename=''): | ||
"""Send an email via the Amazon SES service. | ||
Example: | ||
send_ses('me@example.com, 'greetings', "Hi!", 'you@example.com) | ||
Return: | ||
If 'ErrorResponse' appears in the return message from SES, | ||
return the message, otherwise return an empty '' string. | ||
""" | ||
msg = MIMEMultipart() | ||
msg['Subject'] = subject | ||
msg['From'] = fromaddr | ||
msg['To'] = recipient | ||
msg.attach(MIMEText(body)) | ||
|
||
if attachment: | ||
part = MIMEApplication(attachment) | ||
part.add_header('Content-Disposition', 'attachment', filename=filename) | ||
msg.attach(part) | ||
conn = boto.connect_ses() | ||
result = conn.send_raw_email(msg.as_string()) | ||
return result if 'ErrorResponse' in result else '' | ||
|