learn-amazon-web-services/ses.md at master · dwyl/learn-amazon-web-services

Amazon Simple Email Service (SES) Setup 🔧

This guide takes you through setting up
a verified email address on Amazon SES
and escaping the “sandbox”.

All Software as a Service (SaaS) Products that create value send email.
Even if it’s just a reminder to pay a bill,
an email has to be sent reliably.
Amazon’s SES is a reliable, full featured
and cheap cheapest email service.

@dwyl we rely on email as our primary
feedback loop.
Without email we cannot
communicate
with the people who are using our App.

Amazon Web Services (AWS) Simple Email Service (SES)
lets you send and receive email.
Additionally, for more advanced users SES
has
notifications
with insights
about the email messages you send
e.g: delivery, bounce or complaint.

We are not going to explore notifications in this setup guide,
but we have a Lambda Function: https://github.com/dwyl/aws-ses-lambda
that you should consider exploring if you want a turn-key
solution to your AWS SES needs.

Anyone building an App
who wants to have control over their email.

This guide follows and enhances the official AWS instructions:
https://aws.amazon.com/getting-started/tutorials/send-an-email

Prerequisites:
This guide assumes you already have an AWS account.
Additionally, if you plan to follow along with
the practical side of sending emails,
some familiarity with JavaScript
is advantageous but not required.

Setup 🛠

Login to your AWS account
and visit the SES endpoint:
https://console.aws.amazon.com/ses

02-ses-home

From the SES Home screen, click on “Email Addresses”

1. Verify an Email Address ✉️

In the “Email Addresses” menu, click on “Verify a New Email Address”:

aws-ses-add-email-address

Note:
In our case we had to setup a free Zoho Mail email account
for our domain in order to receive the confirmation email.
See:
issues/35
for detailed steps on how to do this.
It takes around 5 mins.

1.1 Verify this Email Address

Once you have input the desired email address, click “Verify this Email Address”

aws-ses-verify

You should see a messaging confirming that the verification email was sent:

aws-ses-verification-sent

2. Open Email and Click Verification Link 🔗

Open the email client associated with the email address you want to verify,
locate the verifcation email sent by AWS and click the link:

e.g: https://mail.zoho.eu

aws-ses-zoho-mail-verification-email

Once you click the link you should see:

aws-ses-congratulations

If you refresh the AWS you should see that the email address is verified:

aws-ses-email-verified

3. Send a Test Email 📤

In the Amazon SES console,
select the radio button to the left of the email address you just verified,
and then click on “Send a Test Email”:

aws-ses-send-test-1

3.1 Send Formatted Email

Compose and send a Formatted email:

aws-ses-send-test-compose

In your email you should see:

image

3.2 Send Raw Email

Next try sending a Raw email.

aws-ses-send-raw-email

Paste the following text:

Subject: Amazon SES Test
MIME-Version: 1.0
Content-Type: text/html

<!DOCTYPE html

>

<

html

>

<

body

>

<

h1

>

You have successfully sent an email using Amazon SES!

</

h1

>

<

p

>

For more information about Amazon SES, see the

<

a

href

="

http://docs.aws.amazon.com/ses/latest/DeveloperGuide/Welcome.html

"

>

Amazon SES Developer Guide

</

a

>

.

</

p

>

</

body

>

</

html

>

In your email, you should see:

image

4. Escape the Sandbox 👮

At this point you have successfully setup AWS SES,
but you can only send emails to verified email addresses,
which is not much use beyond testing.

In order to send email to any address,
you need to request that AWS remove your account from the “sandbox”:
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/request-production-access.html

In the AWS SES interface, click on the Support selector in the top-right and select “Support Center”:
aws-ses-support

Once in the AWS Support interface, click on “create support case”:
aws-ses-create-case

In the case creation interface, select the “Service limit increase” option:
aws-case-increase-limits

Input the relevant data and then click on “Submit”:

request

aws-ses-click-submit

Once you submit the case you see a summary similar to this:

aws-ses-case-details

A day later … you should expect something similar to this:

aws-ses-setup-out-of-sandbox

5. Send an Email! 💡

Now that you have verified your email address
and you are out of the “sandbox”,
you can send email!

Try following the instructions in:
https://github.com/dwyl/sendemail

6. Create IAM Policy to Send Email from a Lambda Function

If you want to send an email from an AWS Lambda function,
there are a few extra steps to setup an IAM policy to allow this.

On the IAM policies homepage, select Policies and then Create policy:
https://console.aws.amazon.com/iam/home?region=eu-west-1#/policies
aws-iam-lambdases-01-home

Select the JSON tab and paste the json from the instructions,
then click Review policy
https://aws.amazon.com/premiumsupport/knowledge-center/lambda-send-email-ses
aws-iam-lambdases-02-create

Review the policy and name it e.g: LambdaSES
aws-iam-lambdases-03-name
Cant share a link in this description, so just google for
How do I send email using Lambda and Amazon SES

Once you click on Create policy
you should see a confirmation LambdaSES has been created.:
aws-iam-lambdases-04-confirm

Next we need to attach the policy to the existing role.
Search for the policy, select it and
then click on the Policy actions selector:
aws-iam-lambdases-05-policy-action

Attach the policy to the LambdaExecRole:
aws-iam-lambdases-06-policy-attach-to-role

Once you click the Attach policy button,
you should see a confirmation similar to this:
aws-iam-lambdases-07-policy-attched-confirm

This will allow you to send email from a Lambda function e.g:
aws-ses-lambda-test-send

Email received:
aws-ses-lambda-result-email-received

tl;dr > Why Use SES? 💰

AWS Pricing (Lambda + SES) Per Email: $0.0001004

Each email sent has 2 “parts” with corresponding costs.

https://aws.amazon.com/lambda/pricing/

lambda pricing

Lambda Pricing is broken down into two components:

  • $0.0000002 per request (execution cost regardless of duration/memory used)
  • $0.000000208 per 100ms (execution time)

https://aws.amazon.com/ses/pricing/
AWS SES Pricing

Conclusion

We need to make our total (incremental) cost of running
our “Email Solution” significantly cheaper,
while delivering comparable features to other providers.
That’s why we need to use both SES and Lambda
to both send emails and track notifications,
hence: https://github.com/dwyl/aws-ses-lambda

For all companies/teams using AWS sending up to 65,000 Emails a Month
will be Completely Free.
(covered by the free usage tier for the first 12 months).