An Ubuntu VPS on Slicehost: Mail
As mentioned previously, I’ve recently moved this domain over to Slicehost. What follows is Part Three of a guide, compiled from my notes, to setting up an Ubuntu Hardy VPS. See also Part One, Part Two, and Part Four.
Last week I moved this domain’s email to Google Apps. Slicehost has a guide to creating MX records for Google Apps. I have a couple other domains with Google Apps, along with a couple domains hosted locally with addresses that simply forward to my primary, Google hosted, email. I also need to send mail from the server. To accomplish all of this, I use Postfix.
Installing Postfix is a simple matter. Telnet is used quite a bit for testing, so I install that too:
1 |
|
The Postfix setup will ask how it should be installed – we want the “Internet Site” option – and then ask you for your fully qualified domain name.
Done? Let’s make sure Postfix is running:
1 |
|
If it’s working Postfix should return:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 localhost ESMTP Postfix (Ubuntu)
Let’s send a test message from root to the user account user
(replace that with whatever your standard user is):
ehlo localhost
mail from: root@localhost
rcpt to: user@localhost
data
Subject: Test
Hi, is this thing on?
.
quit
Now, check your email as user
by running mail
. See the message? Good.
Open /etc/postfix/main.cf
to make sure that Postfix knows what domains it’s receiving mail for. To do this, edit the mydestination
variable to include all the proper domains. For me, the name of my server looks like server.mydomain.com. I want Postfix to accept mail for that domain, but not for mydomain.com (since that’s being handled by Google Apps), so mine looks like:
mydestination = server.mydomain.com, localhost.mydomain.com , localhost
Restart Postfix if you made any changes:
1 |
|
Right. Now let’s send another test. Notice this time we’re using full domain names, instead of localhost:
1 2 3 4 5 6 7 8 9 10 |
|
Working? Good.
Let’s test from the outside. The first step is to open up the correct ports in the firewall. Assuming you have iptables configured in the way the Slicehost article suggests, open up your /etc/iptables.test.rules
and add the following:
# Allow mail server connections
-A INPUT -p tcp -m state --state NEW --dport 25 -j ACCEPT
Now let’s apply the rules:
1 |
|
Make sure everything looks dandy:
1 |
|
If it meets your fancy, save the rules:
1 2 |
|
And now, from your local computer, let’s test it out.
1 2 3 4 5 6 7 8 9 10 |
|
Now check your mail on the mail server as before. Once again, everything should be working.
Now we need to setup a virtual domain. Remember, I don’t want any virtual users. I only want aliases at a virtual domain to forward to my primary email address. That makes this relatively simple. (Be very, very happy. You should have seen this guide before, when I was still hosting virtual domains with virtual users!) Open up /etc/postfix/main.cf
and add the following:
virtual_alias_domains = myvirtualdomain.com
virtual_alias_maps = hash:/etc/postfix/virtual
Create the /etc/postfix/virtual
file referenced above and add the aliases:
alias@myvirtualdomain.com user@mydomain.com
Turn it into a database:
1 2 |
|
Restart Postfix:
1 |
|
Attempt to send an email to the new alias at the virtual domain:
1 2 3 4 5 6 7 8 9 |
|
The message should now be in your primary email inbox!
As long as we’re setting up forwards, let’s forward system account mail to somewhere where it’ll actually get read. To do so, create a ~/.forward
file with the following contents:
user@mydomain.com
Let’s also create a /root/.forward
, so that roots mail gets forwarded to my local account (where it is then forwarded to my primary email). Root’s forward would simply read:
user
Next up: install Wordpress with rewrites. (Previously, we did a basic setup and installed a web server.)