forked from pythonhacker/rotating-proxy-daemon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathses_email.py
34 lines (29 loc) · 1022 Bytes
/
ses_email.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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('[email protected], 'greetings', "Hi!", '[email protected])
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 ''