AWS Lambda: Sending E-Mail using Python


{
"Statement": [{
"Effect": "Allow",
"Action": [
"ses:SendEmail",
"ses:SendRawEmail"
],
"Resource": "*"
}]
}
import boto3, logging

client = boto3.client('ses')


def lambda_handler(event, context):
logging.info(event)
try:
source_email = event["from"]
to_email = event["to"]
message = event["message"]
title = event["title"]

response = client.send_email(
Source=source_email,
Destination={
'ToAddresses': [
to_email,
]
},
Message={
'Subject': {
'Data': title,
},
'Body': {
'Text': {
'Data': message
},
'Html': {
'Data': '<b>' + message + '<b>'
}
}
}
)
logging.info(response)

except Exception as e:
logging.error(e)
{
"from":"sender@test.com",
"to":"recipient@test.com",
"message":"first message content",
"title":"aws ses test message"
}

Summary

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Agile Project Management

Hassle-free access management with AWS Single Sign-on (SSO)

A new code-efficient CSS pattern for your theming and coloring needs

eSpeak text to speech

Designing User-Oriented Next-Generation 3D Printing Platforms

Extracting black pixels from a specific region of an image and overlaying it on another image

Mostly asked C Interview Questions

Mostly asked C programming interview questions, C interview questions

11 — The Geode Pattern — What is it and how can it be useful for my app?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
cem akpolat

cem akpolat

More from Medium

Connecting to AWS S3 using Athena and performing data analysis

Quick Guide to Setup Ansible AWS Dynamic Inventory

Create a custom analytics server in 30 minutes with Python & AWS

Triggering Lambda with API Gateway to Send a Message to an SQS Queue Using Python