Setup your own email server (MTA) on the cheap - part 1

If you’ve got your own domain, finding a cheap but professional way to host your email can be difficult. Most options either come with a price tag, or recipients get a “sent on behalf of” message in your email headers.

This is a cheap way to build your own email server, without the expense of storing all of your messages… and backing them up.

I deployed an Ubuntu server in AWS. We only need the minimum of storage since we’re not storing anything so this can easily fit in the free tier to cost you nothing for the first year. This server manages email for my personal domains. It scans messages for SPAM and viruses and routes the messages to corresponding Gmail or yahoo mailboxes. The server is also configured to send messages from Gmail or Yahoo using SMTP.


Here’s the setup…
    1. First things, first, let’s update everything:
    sudo apt-get update
    sudo apt-get upgrade

    2. Then install PostFix
    sudo apt-get install postfix

    3. Update the PostFix configuration:

        Edit /etc/postfix/main.cf first:
            a. Find the line “myhostname = …” and set your hostname to something resolvable, e.g. mail.mydomain.com.
            b. Setup forwarding using these lines, make sure you use your domain:
            c. These are optional but I suggest adding these lines to the bottom of your file:
    4. Setup your email mappings by editing (or creating) the file /etc/postfix/virtual. Add a line for each email address you’d like. Put the email addresses for your own domains first, then a tab or space, followed by the external email address the mail should be directed to. You can also put @mydomain.com to send unmatched emails to an external email address. For example:

    emailaddress@mydomain.com gmailaddress@gmail.com
    @mydomain.com gmailaddress@gmail.com

    5. Refresh the postfix configuration:

    sudo postmap /etc/postfix/virtual
    sudo newaliases
    sudo systemctl enable postfix.service
    sudo systemctl start postfix.service

And that’s it. Update your mx records to point to your new server and mail should flow to your external mailboxes.

Next steps (I’ll make these links as I add the following posts):

Big thanks to these sources:

Setup Steps with links:
  1. Setup PostFix with email address forwarding
  2. Setup sending and use LetsEncrypt to secure the SMTP server 
  3. Setup SPAMAssassain so Gmail or Yahoo don’tblock us for passing on dodgy emails 
  4. Setup ClamAV to block viruses, these will get you blocked too 
  5. Setup DKIM using opendkim to check DKIM on incoming and sign our outgoing mail 
  6. Update sender addresses so SPF passes for forwarded messages 
  7. Use Fail2Ban to block brute force attempts on our server

Comments

Popular posts from this blog

Sync iTunes with MythMusic

Using Homebridge and Broadlink RM Mini to automate

LetsEncrypt and AWS ELB Load Balancers