-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendMail.py
31 lines (22 loc) · 881 Bytes
/
sendMail.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
import smtplib
from email.message import EmailMessage
import ssl
def lambda_handler(event,context):
# print(event)
if(event['Records'][0]['eventName'] == 'INSERT'):
MailID = event['Records'][0]['dynamodb']['Keys']['MailID']['S']
OTP = event['Records'][0]['dynamodb']['NewImage']['otp']['N']
sender = "[email protected]"
password = ''
Subject = "OTP for server"
body = "OTP: {}".format(OTP)
em = EmailMessage()
em['From'] = sender
em['To'] = MailID
em['Subject'] = Subject
em.set_content(body)
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com",465,context=context) as smtp:
smtp.login(sender,password)
smtp.sendmail(sender,MailID,em.as_string())
return "Mail sent!"