Postfix Email Server integration with SES
Have you ever thought of setting up your web or application server with your own email server? Well, when you set up an application it is likely to have your own email server to handle incoming and outgoing mail to your domain. Before I get into my topic I assume that you got some basic knowledge of AWS.To explain how to set up a simple postfix email server with AWS SES to handle all your email. We have two phases in this implementation.
*Configure SES with Domain
*Configure postfix and integrate with SES on EC2
Configure SES with Domain
Amazon SES requires that you verify your email address or domain, to confirm that you own it and to prevent others from using it. When you verify an entire domain, you are verifying all email addresses from that domain, so you don’t need to verify email addresses from that domain individually. For example, if you verify the domain example.com, you can send an email from [email protected], [email protected], or any other user at example.com. Let's verify our domain name with SES.
*Go to the AWS console management and click on the SES.
*Click on the Domain available on the left top corner.
*Click verify new Domain.
*On the Verify a New Domain, for Domain, type the name of the domain that you registered using Route 53, and then choose Verify This Domain.
*On the Verify a New Domain dialog box, choose Use Route 53. Your Domain Verification and Email Receiving Record will be updated in Route 53
Note: If you don’t see Use Route 53 your domain may not be registered with Route 53.
*Once verified your domain, you can use any email address from this domain as your email.
*To establish the connection between postfix and SES you will need an SMTP credential.
*Now choose the SMTP settings in the same SES console.
*Choose to Create My SMTP Credential.
*Give the user name and click create.
*Download the credentials this will be used when you configure the server
Configure postfix and integrate with SES on EC2
In this section, you are going to install and configure postfix on the EC2 instance.
*You should have an up and running EC2 machine.
*Open port 25(SMTP) and 22(SSH) for all security groups.
Let's log in to the machine using putty or ssh client. Now need to create a domain on Route53.
*Go to the AWS console and choose Route53.
*Choose Hosted Zone and select your domain where you wish to configure.
*Click on create a record set to add a new recordset, then select A-IPv4 address for the resource type.
*Add subdomain name in the Name field and enter a record value that is your EC2 IP.
*Set the desired TTL
*Then click on Create button.
Now we will install Postfix on our EC2 machine.
#sudo apt-get update
#sudo apt-get install postfix
Now we need to make some changes in postfix configuration file. Lets do it one by one.
To integrate our postfix with SES we need to add some more line in main.cf.
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
myhostname = example.com
myorigin = /etc/mailname
relayhost = [email-smtp.us-east-1.amazonaws.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_tls_note_starttls_offer = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
NOTE:Value of relay host will change depending upon SES region you use.Comment out of the following line of master.cf file by putting # infront of it:
Edit the file /etc/postfix/sasl_passwd if not present please create it
NOTE: Add your SMTP username and password that you downloaded.
Save and close the file and use the below command to create a hashmap database.
#sudo postmap /etc/postfix/sasl_passwd
STOP AND START POSTFIX
#sudo service postfix stop