Skip to content

Instantly share code, notes, and snippets.

@medmin
Created September 18, 2019 03:00
Show Gist options
  • Save medmin/572ba440dd4d6eafe1271a059b979162 to your computer and use it in GitHub Desktop.
Save medmin/572ba440dd4d6eafe1271a059b979162 to your computer and use it in GitHub Desktop.
Send Email with gmail account in aws lambda
import json
import smtplib, ssl
port = 587 # For starttls
smtp_server = "smtp.gmail.com"
sender_email = "[email protected]"
receiver_email = "[email protected]"
password = "xxxxxx"
message = """\
Subject: Test
This message is sent from Python by AWS."""
def sendmail():
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.ehlo() # Can be omitted
server.starttls(context=context)
server.ehlo() # Can be omitted
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message)
def lambda_handler(event, context):
# TODO implement
sendmail()
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment