Postfix Email Server integration with SES

July 7, 2016 | Comments(1) |

Have you ever  thought of setting up a web or application server with your own mail server? Have you ever tried to do so and stuck at some point? Well, when you host a website or your application it is likely to have your own mail server to handle incoming and outgoing mail to your domain. Before I get into my topic, I assume that you have got basic knowledge on AWS. For any kind of cloud training please visit www.cloudthat.com. Here, I’m going to explain you how to setup a simple postfix email server with AWS SES to handle all your email needs of the application. AWS SES (Simple Email service) is a cost effective email service built on AWS cloud. You will be launching an Amazon EC2 machine to setup your email server. Let me put it in this way. We have got two phases in this implementation.

  1. Configure SES with your Domain
  2. Integrate postfix with SES on an EC2 machine

Configure SES with your Domain

Domain name is essentially the name given to your website, which helps the visitors to remember the site. For example, we have got a domain cloudthat.com and we have the websites like blog.cloudthat.com, training.cloudthat.com with different purpose. Lets come to the Email part. Email address will be always with a domain name. In order to send a mail through SES we have to verify our domain name so that we can use any Email ID with this domain name as from address. Let’s verify our domain name with SES.

  • Go to AWS console and click on SES
  • Click on “Verify new Domain” to verify your Domain.

1

  • This step will verify your domain. Once you verify, you can use any mail address from this domain as your from address.
  • For the time being I’m verifying my own mail id which we will use as a from address.
  • Click on Email address and verify your email ID

11

  • Enter your email ID and verify it

12

  • To establish the connection between your mail server and SES you need to create SMTP credentials.
  • Now click on SMTP setting and create SMTP credentials

13

  • Give your user name and click on create

14

  • Download your credentials and close. This will be used when you configure your server.

15

Note: This will create an IAM user for you with needed SES privileges.

Integrate postfix with SES on an EC2 machine

In this phase you are going to launch an EC2 machine. Then you will install postfix as your mail transfer agent (MTA) and configure your postfix to talk to SES which we configured now. Let’s go step by step to configure the mail server.

  • Launch an EC2 machine with Amazon Linux AMI
  • Open port 25(SMTP) and 22(SSH) for all in security group

Now let’s login to our machine using putty or any SSH client. First, make sure to set the hostname.

We will install postfix as our MTA to send and receive mail.

We need to make minimum changes in postfix configuration to enable our mailing service. Let’s do it one by one.

To integrate our postfix to SES we need to add few more lines to main.cf file.

Note:Relay host will change depend upon the SES region you use. To get the SES end point visit Regions and Endpoints.

Comment out the following line of the master.cf file by putting a # in front of it:

Edit the /etc/postfix/sasl_passwd  File. Create the file if it does not exist

Note: Add your SMTP username and password which you downloaded. Save and close the file use the following command to create a hashmap database file containing your SMTP credentials.

Now we have to tell postfix where to find CA certificates. This is very much needed to verify the Amazon SES server certificates.

Stop and start postfix

We are ready with your mail server. Lets send a test email.

Note: you must replace from@example.com with your “From” email address, which you must have previously verified with Amazon SES. Replace to@example.com with your “To” address. If your account is still in the sandbox, the “To” address must also be verified.

Pricing

  • You can send 62,000 messages per month to any recipient when you call Amazon SES from an Amazon EC2 instance directly for free.
  • Email messages are charged at $0.10 per 1,000 after your free tier.

One Response to “Postfix Email Server integration with SES”

Leave a Reply