-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSES.py
64 lines (58 loc) · 2.08 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'''
Note: https://www.learnaws.org/2020/12/18/aws-ses-boto3-guide/
'''
import boto3
class AmazonSES(object):
def __init__(self, region, access_key, secret_key, from_address, charset = "UTF-8"):
self.region = region
self.access_key = access_key
self.secret_key = secret_key
self.client = boto3.client("ses",
region_name=self.region,
aws_access_key_id=self.access_key,
aws_secret_access_key=self.secret_key
)
self.CHARSET = charset
self.from_address = from_address
def send_text_email(self, to_address, subject, content):
response = self.client.send_email(
Destination={
"ToAddresses": [
to_address
],
},
Message={
"Body": {
"Text": {
"Charset": self.CHARSET,
"Data": content,
}
},
"Subject": {
"Charset": self.CHARSET,
"Data": subject,
},
},
Source=self.from_address,
)
def send_html_email(self, to_address, subject, content):
response = self.client.send_email(
Destination={
"ToAddresses": [
to_address,
],
},
Message={
"Body": {
"Html": {
"Charset": self.CHARSET,
"Data": content,
}
},
"Subject": {
"Charset": self.CHARSET,
"Data": subject,
},
},
Source=self.from_address,
)