Have you ever considered setting up an application or web server with your own mail server. You may have tried it once and failed. You will likely have your own mail server if you host a website, or an application. This allows you to manage incoming and outgoing mail from your domain. Before I go into my topic, let me assume you are familiar with AWS. Cloud training can be found at www.cloudthat.com. Here I will show you how to set up a simple postfix email server using AWS SES. This will allow you to manage all your email needs. AWS SES (Simple Email Service) is an affordable email service that uses AWS cloud. To set up your email server, you will need to launch an Amazon EC2 machine. Let me explain. This implementation has two phases.
Configure SES with Domain
Integrate postfix and SES on an EC2 Machine
Configure SES with Domain
Your domain name is the name you give to your website. This helps visitors remember it. For example, we have got a domain cloudthat.com and we have the websites like blog.cloudthat.com, training.cloudthat.com with different purpose. Let’s get to the email part. An email address will always be associated with a domain. To send mail through SES, we must verify our domain name. This will allow us to use any Email ID that is associated with this domain as the from address. Let’s verify the domain name with SES.
Click on SES in the AWS console
To verify your Domain, click on “Verify new domain”.
This will verify your domain. Once you have verified your domain, you can use any mail adress from this domain to be your from address.
At the moment, I am verifying my mail id and will use it as a from address.
Click on Email address to verify your email ID
Verify your email ID by entering it
You will need to create SMTP credentials in order to establish the connection between your mail server & SES.
Click on SMTP Setting to create SMTP credentials
Click on create to give your user name.
Close the browser and download your credentials. These credentials will be used to configure your server.
Note: This will create an IAM account for you with the required SES privileges.
Integrate postfix and SES on an EC2 Machine
This phase will see you launch an EC2 server. Next, you will install postfix (mail transfer agent) and configure postfix to talk with SES. Let’s take it step by step to set up the mail server.
Amazon Linux AMI allows you to launch an EC2 machine
All security group members can open port 25 (SMTP) or 22 (SSH).
Let’s now login to our machine with putty or another SSH client. First, set the hostname.
$vim /etc/hosts127.0.0.1 mail.yourdomain.com12$vim /etc/hosts127.0.0.1 mail.yourdomain.com
$vim /etc/sysconfig/network# …HOSTNAME=mail.yourdomain.com# …1234$vim /etc/sysconfig/network# …HOSTNAME=mail.yourdomain.com# …We will install postfix as our MTA to send and receive mail.
$ sudo: yum – install postfix1$ sudo: yum – install postfix We need to make the minimum changes to postfix configuration in order to enable our mail service. Let’s take it one at a time.
Shell$vim /etc/postfix/main.cfmydestination = $myhostname, localhost.$mydomain, localhost, $mydomainmydomain = yourdomain.commyhostname = mail.yourdomain.commynetworks_style = hostmyorigin = $mydomain123456$vim /etc/postfix/main.cfmydestination = $myhostname, localhost.$mydomain, localhost, $mydomainmydomain = yourdomain.commyhostname = mail.yourdomain.commynetworks_style = hostmyorigin = $mydomainTo integrate our postfix to SES we need to add few more lines to main.cf file.
Shellrelayhost = [email-smtp.us-west-2.amazonaws.com]:25smtp_sasl_auth_enable = yessmtp_sasl_security_options = noanonymoussmtp_sasl_password_maps = hash:/etc/postfix/sasl_passwdsmtp_use_tls = yessmtp_tls_security_level = encryptsmtp_tls_note_starttls_offer = yes1234relayhost = [email-smtp.us-west-2.amazonaws.com]:25smtp_sasl_auth_enable = yessmtp_sasl_security_options = noan