Previously I talked about our adventure moving to the Linode.com service. Now that the websites have been running spectacularly for a few a week, I noticed that emails were not being sent or received properly from some of the domains. Doh! See how we fixed it.
For our sites, we like Gmail. So I want all my domains to be sent to my Gmail account. This is where we need to setup postfix to forward email for these domain names to a few Gmail account. Below we talk about how we made it happen.
To back up a few steps, I’ll explain what was already installed. We chose to use postfix instead of sendmail because of the security issues surrounding sendmail.
sudo apt-get install postfix
sudo dpkg-reconfigure postfix
Setup Domain Catch-all Aliases
We chose the Internet Site option, set postfix mail domain to our domain name (e.g. example.com). Hmmmm…. so why is it not working. Remember in the previous article I said it had been many moons since I did Unix or Linux admin? Well, I guess I should have added that I have never setup a mail server on Linux.
Thanks to the first two sections of this article we got email working.
Step 1.
sudo vi /etc/postfix/main.cf
and change this to myhostname to localhost
myhostname = localhost
Step 2
Add the following lines to the main.cf file as well.
virtual_alias_domains = example1.com example2.com
virtual_alias_maps = hash:/etc/postfix/virtual
The virtual_alias_domains is a space separated list of the domain names that you want postfix to handle mail for.
Step 3
Now we need to create the virtual alias map file
cd /etc/postfix
sudo vi virtual
Now you have just created the file named virtual. Add a mapping of where to send the emails for the various domains and email addresses.
First we will deal with the catch all forwarding. The format is the domain name then a space and then the email address you want all emails to go to if they don’t match a particular email address.
@example1.com myusername@gmail.com
@example2.com myusername@gmail.com
Next you can add specific email address mappings instead of the catch alls. This format is similar and starts with the specific domain email address, a space and then the forwarder email address.
admin@example1.com myusername@gmail.com
webmaster@example1.com otheruser@gmail.com
Step 4
Now we need to create the hash map the speeds up how postfix reads these virtual mappings.
cd /etc/postfix
sudo postmap virtual
Step 5
Finally we restart postfix
sudo /etc/init.d/postfix restart
Networking
Woohoo, we are now sending email….short-lived celebration though. Still not receiving email to these addresses from outside the server. hmmmm….
Okay, I’m not a rocket scientist. After about 15 minutes of checking config files, logs and such I finally just tried to telnet to port 25 on the server. Yup, no answer at all.
In my haste to lock down the server last week, I had not opened port 25. A quick change to the firewall and we are good to go. Sending and receiving emails for the mapped domains works wonderful.
sudo ufw allow 25/tcp
You could stop here, but again, I’m a bit paranoid.
Use this tool to ensure you are not a bad netizen by providing an open relay server.
Blacklist with Linode IP?
Now, this last bit was specific to our Linode service and the IP address assign in the specific datacenter we are located in. Your mileage may vary. It was noticed that when sending email to a particular user, the message was returned with a 554 message rejected response.
A bit more investigation and we found that the reason was due to our ip address being listed in the SORBS database. Apparently our IP is registered as being a Dynamic User/Host List (DUHL). Essentially, they think it is a dynamically assigned IP address such as those used for home ISP users. A little bit of reading and we submitted our request to have our IP address de-listed. I guess we’ll have to wait a bit to see what happens.
Blessings.
Popularity: 5% [?]