Personal Email Server with Ubuntu and Losing Network on Virtual Appliances
Yesterday, before leaving for work, I seriously FUBAR'ed my RSS reading email setup to the point where it wouldn't get past the "A's" in the feed list. Before that, a couple of weeks ago, I ended up with a huge regular email mess because:
- Some spammer used my email addresses as the "FROM" on a bunch of spam.
- A major bank in South Africa was the recipient of a LOT of those spam messages.
- Said bank decided to bounce each and every one of them to the "FROM" address: me.
- I only managed to get the sandbags in place after 31,000 of those bounced messages came through.
And, before that, I had my personal mail server needing to be reinstalled and messed with because the junk account to which all spam was directed reached a size that Mercury Mail couldn't handle. Finally, the Windows machine that is serving as my mail server (and a bunch of other uses) is going to be replaced as it moves into a role as a Call of Duty 2 server. I was really not looking forward to carrying the existing mail setup (the only thing on this machine that's problematic to move) into the new setup.
With all of that weighing heavily on the email portion of my geek setup, last night I decided to tackle something that's been on the TODO list for something like 3 years: a personal Linux email server to handle all of this crap in a more industrial approach. Further, I want all of this in a VMWare virtual appliance so I can easily back it up, move it between different hardware, take it with me on a portable drive, etc.
I've taken half-hearted stabs at this setup before, and stopped before any of it really worked, so I was deeply amazed when I was actually able to get to a basic functioning setup in a couple of hours last night. Here's the basic set of requirements I've got in order to call this thing "done".
- Server does not have a domain of its own.
- Fetches mail from an arbitrary number of POP3 mailboxes to appropriate user accounts.
- IMAP access to MailDir setup of those mailboxes.
- Outbound email sent via smarthost through outbound.mailhop.org.
- My entire chain of tools for RSS reading installed and routing feeds to one of the IMAP mail accounts.
- Spam and virus filtering (though I'm willing to let this slide until after migration if I can't do it the ideal way).
- Automatic cleanup and archiving of email.
- Access will be via SSH tunneled ports to localhost. All access will be "local".
Things I'd like to see, but don't need to happen before migrating off of the old setup.
- LDAP server for contacts.
- Whitelisting any email from someone in LDAP server.
- Procmail rules to enhance pre-processing of my email.
I've used literally a dozen or more different guides to set up email servers on Linux. And, without fail, until last night, they all broke down at some point. Most of them focused on how to set it up if you are setting up a "real" mail server, i.e. one that has a domain and sends and receives email for that domain. I'm not going to register a new domain just for this because it's for collecting the email I already get. In other cases, by the time I'd reached step 2 or 3 and the instructions said: "you should see XYZ at this point and that means it's working", I'd see nothing of the sort and there were no followup instructions on what to do if you didn't see what the tutorial mentioned.
This time around, I went with the instructions from Spencer Stirling. They worked, but not because they matched up exactly. It's just that where they didn't match my reality, they were either close enough or it didn't matter and it still worked anyway. I didn't do any of the security bits yet, but plan to put them in place where it makes sense for my setup.
So, what's working as of tonight (after the 2 hours last night and a bit of futzing this morning before work) is:
- Ubuntu Edgy Server in VMWare running and patched
- Exim4 running
- Fetchmail running
- Courier IMAP running
- Mutt is running and reading email
- Squirrelmail installed and working with IMAP
- LAMP stack installed for PHP tools for RSS
- PHP-CLI installed for commandline scripting of RSS tools
- Basic documentation page started in the server's web server for things I need to remember how to do down the road, like set up new users and links to the tutorials I used to set it up.
- Email from one of my legacy email addresses is getting fetched and delivered appropriately by fetchmail.
All in all, looking good. Well before the migration needs to happen, I'll be there for regular email and the RSS setup should be close behind.
That is, until I tried to run this virtual appliance on another computer. Suddenly, the only network interface available was the loopback to 127.0.0.1. While there truly is no place like home, I'm not thrilled when it's the only place you can go.
Turns out that, unlike Ubuntu Workstation, Ubuntu Server does this thing where, if it gets a new MAC address on a network card, it won't use it on the same network config. Since VMWare hands out new MAC addresses on the virtual network cards like candy, this is likely to be a huge problem for anyone who intends to use VMWare appliances on more than one machine.
After a lot of brow furrowing, I finally found a solution. This forum posting explains what exactly is going on (though from the perspective of a rare move between hosts).
Here's the script mentioned in the forum posting that "resets" the MAC address/networking when this happens. Put it in /usr/sbin/ under something like "fixmac" and make it executable (chmod +x fixmac). Then, when this happens, log in and run it as root and reboot. It will be back to normal.
mac=`ifconfig -a | grep "HWaddr" | cut -d " " -f 11`
echo "eth0 mac $mac arp 1" > /etc/iftab
This is still a pain though and I'm looking for a better option long term as I don't want to have to go through that every time I move it (which is likely to be more than once per day). At any rate, given the difficulty I had in finding the source of the problem, I thought I'd share what a fix is.


February 1st, 2007 at 5:56 am
As of this morning, all of my regular email is now going through the virtual mail server and appears to be chugging along. Fetchmail's been running periodically according to the cron schedule and there were a couple of hundred messages in my inbox this morning.
On the RSS end, I'm running into a snag that the PHP IMAP setup doesn't seem to want to connect to this IMAP server. I'm pretty sure it's because, when I added php5-imap to the mix, I answered the question about libc-client with Maildir the wrong way (because I've always answered the wrong way in the past). And, I can't figure out how to get it to ask me for it again. I tried removing and adding again and it didn't do it. I also tried to reconfigure the package and it asked a bunch of other questions, but not that one. Hmmm.
February 1st, 2007 at 9:08 am
Hey, just got my first notice of a blocked malware/virus message snagged by ClamAV. I hadn't gotten around to testing that yet, but apparently I don't need to as the malicious world took care of kicking off the test for me.
February 1st, 2007 at 7:22 pm
Hey J:
I wanted to say thanks for your earlier articles on IMAP and Thunderbird. I wasn't interested in using smtp to send articles to my account, so I recently setup feed2imap on my new ubuntu box. It works great, but I just have them sent to a free IMAP account I use for reading. I copy the articles I wish to save to my primary IMAP account at tuffmail. With your suggestions and the helpful link, I might consider setting up a local mail server like you've done.
Thanks again,
PM
February 2nd, 2007 at 7:17 pm
Glad I could help. This setup keeps getting better and better. Once the entire setup is under your control, you can do *anything* you want with it and I'm really starting to come up with some ideas of what to do with my email. I've already written up some tools that sort and archive email as well as re-marking as UNSEEN those messages I indicate need a response. Over the last 2 days, I've gotten my inbox *greatly* reduced in backlog.
I've been dragging it back and forth on my 60GB portable drive and it's worked like a charm after the first couple of hiccups.