How To Send An Email Using Amazon Simple Email Service (SES) Part-(3 of 3)
In this article, we will explore step-by-step Sending An Email Using AWS SDK. We will use Go AWS SDK. Don’t worry if you are not familiar with Go Programming Language. I will explain every single detail. Hope this will give you a solid idea on AWS SDK for SES APIs and you can implement on your preferred Programming Language.
By the end of this tutorial:
- We will have a solid understanding of AWS SES.
- We will be able to send an email using AWS Go SDK.
To follow this tutorial, you will have to have the following:
- AWS account.
- Go (Golang programming language) install on your development machine.
Send Email using AWS SDK for Go
Amazon’s simple email service (Amazon SES) allows developers to programmatically send emails through Amazon’s servers from any email address that they have verified in their AWS account.
If you follow the first part of this AWS SES series you can skip Verify Email Address with Amazon SES.
If you don’t have an AWS account, go to this link create your account, you will get 12-month free trial all most of the AWS services. Awesome right. Visit aws.amazon.com/free for full offer terms
- Sign in to the AWS Management Console
and open the Amazon SES console at https://console.aws.amazon.com/ses/
2. With your new AWS account, or you have not requested a sending limit, your account in the Amazon SES sandbox with limited feature. This means that you will not be able to send email to addresses that aren’t verified with AWS. So you will need to verify email addresses whatever email address you plan on using for this service.
3. Enter the Email that you want to verify (make sure you own the Email) and select “Verify This Email Address”. Amazon will send you an email with a link to verify that email address with Amazon SES.
4. In Amazon SES console, under Identity Management, choose “Email Addresses” to view the email address that you verified.
5. Install the AWS SDK
6. We need to create an AWS access key. Log in to your AWS account. In your amazon management console, click “My Account” in the top right corner and then select “Security Credentials”.
7. This will take you to the “Your Security Credentials” page where a modal will give you the two option to “Continue to Security Credentials” or “Get Started with IAM Users”. Select “Continue to Security Credentials”.
8. Select “Create New Access Key”. You will get the “Create Access key” modal.
9. Download the key file and open the file in your favorite text editor. These are your root AWS access keys. Keep them secret and safe.
10. Finally, it’s time to create our send emails service. The service uses Amazon SDK for Go APIs to create and send emails.
First, we need to initialize a couple of constants for the emails.
Now, we will create a session for our sending email method. Amazon SDK required session.
In the AWS SDK for Go, a session is an object that contains configuration information for service clients. which you use to interact with AWS services. For example, sessions can include information about the region where requests will be sent, which credentials to use, or additional request handlers. Whenever you create a service client, you must specify a session. For more information about sessions, see the session package in the AWS SDK for Go API Reference.
The SendEmail method will use the recipient, subject, HTML body, sender and our created session.
We now ready to send our email.
Here you can find full codebase on GitHub.
Boom check your email inbox. We successfully send email using AWS SDK for Go.
I hope you enjoyed the tutorial. Let me know if you have any suggestion on my post in the comments. Thank you for going through this lengthy post. I will be glad if you can share your thoughts with me on Twitter.
You can find it on GitHub.
If you’re looking for a developer or considering starting a new project, I am ready to help! Feel free to DM me on Twitter.