Quick how-to: (Sub)Domain forwarding Email in Qmail (with virtual domain support)
As part of an ongoing Server move, today I needed to find a way to divert/forward all incoming Email from one Server (Server A) to another Server (Server B). Server A is running Qmail (on Debian etch) with virtual domains as part of a Plesk 8 install (alongside Courier). Server B is running my preferred setup of Postfix and Dovecot.
After a bit of searching, I found a good article describing “forwarding Email to another host” using Qmail. I tried, as the article recommends setting up a Qmail config file (which didn’t exist on my server):
Containing a Qmail Email domain forwarding rule e.g.:
Unfortunately after restarting Qmail there was no change.
So I then thought a little further and realised that as part of Plesk 8, Qmail was being run with virtual domain support (i.e. Email accounts are stored in a Database rather than as system accounts/files) and spotted a Qmail config file:
This config file contained the name of the domain I was trying to forward followed by a colon and a number, I assumed it was likely that the number was some sort of ID. So, I tried removing the line containing the domain I was trying to forward, restarted Qmail and bingo! Email forwarding was working in Qmail…Nice!
So, as a brief recap, the process is:
- As always: Back up all your current, working config files and if at all possible, do this using a test domain or sub-domain name so if you make mistakes you won’t be killing peoples email!
- Set up your destination Email Server to receive Email for the relevant (sub)domain and Email account(s).
- Ensure that the domain name you are trying to forward Email for is in the Qmail config file /var/qmail/control/rcpthosts (this ensures that Qmail will handle Email for the domain).
- If necessary create the Qmail config file /var/qmail/control/smtproutes (this file did not exist on my server).
- Add a forwarding rule to /var/qmail/control/smtproutes e.g.
Note that you can use sub-domains if you want to e.g.
or you can forward to an IP address e.g.
If you want to forward all Email for all domains handled by your Qmail Server, you can use a wildcard config which means you omit the source domain name e.g.:
or if you want to forward all Email being handled by your Qmail Server:
- If your Qmail installation is running virtual domains (as was the case with my Plesk 8 install), remove the line containing the domain you are trying to forward to which would look something like this:
- Now you should be finished with config so you can restart Qmail:
- Check your destination Email Server which should now be receiving Email sent to Server A for the source domain.
This worked fine for me using (source server) Debian Etch/Plesk 8/Qmail and destination server Debian Lenny/Postfix with virtual domains. Please be sensible though, no one likes losing Email so proceed with a little caution.
I assume that config file locations may vary on different installs so the path to config files may be different on your Qmail server.
I hope this article is useful and works for you too!
|This entry was posted by Neil Craig on April 22, 2010 at 8:48 pm, and is filed under Email, Qmail, Sysadmin. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site.|
No trackbacks yet.
about 1 year ago - 3 comments
AS I type, i’m setting up an Ubuntu server to use a virtual server host on my test rig. Slight problem though, after getting bored/frustrated with command line configuring (odd because usually command line is my preference) I got lazy and decided to install Gnome and virt-manager. All good, so I thought, I added xrdp More >
about 1 year ago - No comments
It’s been quite some time since I’ve posted an article here and this one will be very brief… If you feel so inclined and are able, please consider sponsoring the UK National Computer Archives Colossus display. More information can be found here: http://www.colossusonline.org/ I’ll soon be posting on my findings over the last year or More >
about 2 years ago - 12 comments
I’ve just been creating the HTML for an Email to be sent out on behalf of a client and have found what appears to be a bug in Outlook 2007 & 2010 (which use the MS Word rendering engine) when using tall images in HTML Emails. My HTML Email was created from a JPEG designed More >
about 2 years ago - 2 comments
As every web-developer knows, testing your Web pages on the myriad of popular Web browsers can often be a horrible experience…and if there’s one thing which is even worse than testing web pages in different browsers, it surely has to be testing HTML Email layout in multiple Email clients!
about 3 years ago - No comments
Lighttpd is an alternative to the very popular Apache web-server – I have just found out that Lighttpd can draw it’s vhost configuration from a MySQL Database which is definitely a one-up on Apache, at least as far as I know.
about 3 years ago - 1 comment
We’ve recently been working on a Web-Server migration for a regular client at work, part of which involved transferring the MySQL Databases (or strictly the schemas) for each of their websites from their old Web-Server to the shiny new replacement. In doing this, I rediscovered a really handy method which really simplifies transferring MySQL data More >