generated from oceanhackweek/ohwyy_proj_template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAWS-SES-SendAcknowledgement.py
72 lines (59 loc) · 1.87 KB
/
AWS-SES-SendAcknowledgement.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
65
66
67
68
69
70
71
72
# %% import packages
import boto3
from botocore.exceptions import ClientError
import pickle as pkl
# %% Load email list
# file = 'pickle_file_containing_a_list_of_emails.pkl'
# with open(file, 'rb') as f:
# email_list = pkl.load(f)
# temporary variable for testing
email_list = ["[email protected]"]
def create_email_content(location):
subject = "MMWIH: Congratulations, you are on the hotlist"
body = (
f"Hello,\n\n"
f"You want us to message you when it is hot at " + location + ".\n\n"
f"This is a notification that your email has been added to our records, and you will receive an email when it is hot.\n\n"
f"The MMWIH team\n\n"
)
return subject, body
location = 'Maria Island'
subject, body = create_email_content(location)
def send_email():
# Create an SES client
ses_client = boto3.client('ses', region_name='ap-southeast-2') # Change the region if needed
# Email settings
SENDER = "[email protected]"
RECIPIENT = "[email protected]"
SUBJECT = subject
BODY_TEXT = body
CHARSET = "UTF-8"
# Try to send the email.
try:
response = ses_client.send_email(
Destination={
'ToAddresses': [
RECIPIENT,
],
},
Message={
'Body': {
'Text': {
'Charset': CHARSET,
'Data': BODY_TEXT,
},
},
'Subject': {
'Charset': CHARSET,
'Data': SUBJECT,
},
},
Source=SENDER,
)
except ClientError as e:
print(e.response['Error']['Message'])
else:
print("Email sent! Message ID:"),
print(response['MessageId'])
# Call the function to send an email
send_email()