-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathses.py
44 lines (41 loc) · 1.35 KB
/
ses.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
34
35
36
37
38
39
40
41
42
43
44
from boto3 import client
class SES(object):
"""Example class to demonstrate SES actions"""
def __init__(self, *args, **kwargs):
region_name = self.kwargs.get('region_name', 'us-east-1')
self.conn = client('ses', region_name=region_name)
def send_email(self, sender, to, subject, body):
"""
Send email.
Note: The emails of sender and receiver should be verified.
PARAMS
@sender: sender's email, string
@to: list of receipient emails eg ['[email protected]', '[email protected]']
@subject: subject of the email
@body: body of the email
"""
try:
response = self.conn.send_email(
Source=sender,
Destination={
'ToAddresses': to
},
Message={
'Subject': {
'Data': subject,
'Charset': 'UTF-8'
},
'Body': {
'Text': {
'Data': body,
'Charset': 'UTF-8'
}
}
}
)
if response['ResponseMetadata']['HTTPStatusCode'] == 200:
return True
else:
return False
except:
return False