header image
 

Qmail Howto

I wrote this guide for a couple of reasons. First, the existing qmail guides that I've found on the net did not provide a complete qmail solution. My first qmail installation was such a pain for me, that I had to go through a tough qmail learning process (yes, qmail can sometimes be a real pain, especially for newbies) and discover some things by myself. Of course, such great Internet resources as mailing lists and other qmail contributions made my life a lot easier :-) Konstantin Riabitsev's "Qmail-Vmailmgr-Courier-Squirrelmail Installation Guide" was the first guide that really helped me out. That's where I borrowed some stuff from while writing this guide -- of course, with his agreement. Second, I simply love qmail and would like to contribute to its development, even a little bit. Third, I think that many admins out there will find this guide useful and practical. And fourth, every once in a while I do install qmail on different servers for various reasons and I simply got tired of carrying installation notes with me all the time. So, in a way, this guide is for myself too ;-)

Full Qmail Installation and Configuration Guide
or
Qmail + Vmailmgr + Tcpserver + RBL + SpamAssassin + Relay-CTRL + Qmail-Scanner + Courier IMAP Guide + POP3S + SMTPS

1) Who should use this guide?
Anyone who wants to install a complete qmail solution.

2) Can this guide be used for productive systems i.e. big servers?
It sure can. I've done some qmail installations in productive environments with many simultaneous users. And it works perfectly!

3) What about security?
Well, security has never been a problem with qmail. I haven't heard of anyone breaking NetQmail version 1.05 (the one we'll be installing). As for everything else we'll be doing here, many people find it pretty secure.

4) On what operating systems has this guide been tested on?
I've done testing mostly on Linux machines (Fedora, Redhat, Debian, Mandrake). So, I could say that everything should work flawlessly on any linux machine. It should also work on BSD systems.

5) Stuff we'll be needing (sources)
Download the following sources to a src directory i.e. /usr/local/src

Qmail-related stuff:
- NetQmail v1.06 from http://www.qmail.org
- Qmail Patches from http://megaz.arbuz.com
- VMailMgr v0.97 from http://untroubled.org
- VMailMgr Tools v0.2 from http://untroubled.org
- Relay-CTRL v3.1.1 from http://untroubled.org
- Qmail-Autoresponder v0.97 from http://untroubled.org
- Ucspi-UNIX v0.36 from http://untroubled.org
- Ucspi-TCP v0.88 from http://cr.yp.to
- Daemontools v0.76 from http://cr.yp.to
- Courier-IMAP v3.0.8 from http://www.courier-mta.org
- MailDrop v2.0.4 from http://www.courier-mta.org
- TNEF v1.4.4 from http://sourceforge.net/projects/tnef
- SpamAssassin v3.2.5 from http://spamassassin.apache.org
- Qmail-Scanner v2.05 from http://qmail-scanner.sourceforge.net
- Stunnel v3.26 from http://www.stunnel.org

For domain administration (via www) *:
- oMail-admin v1.2rc1 from http://omail.omnis.ch/

* I'm assuming that Apache web server and PHP are both installed, configured and fully operational on the machine you are installing qmail on. If you haven't yet installed Apache, there is another guide written by me which covers Apache installation with modules such as PHP. It can be accessed from here.

6) First things first
First, we'll have to get rid of your existing e-mail server. If you have just finished installing Linux on your machine, most probably sendmail is also installed. So, let's remove sendmail from your machine:

# rpm -q -a | grep sendmail
sendmail-8.13.8-2
sendmail-cf-8.13.8-2
sendmail-devel-8.13.8-2 # rpm -e sendmail --nodeps
# rpm -e sendmail-cf --nodeps
# rpm -e sendmail-devel --nodeps

This should get rid of all sendmail files on your machine.

If you have a FreeBSD system, run pkg_info | grep sendmail to see if you have sendmail installed on your system. If you do, run pkg_delete to get rid of sendmail completely.

7) Patch and Install Qmail
All right, now we are going to install Qmail from downloaded sources. We'll apply some necessary patches to Qmail, to make sure that the solution we are going to implement works perfectly.

OK, so first, we untar qmail and change directory to qmail sources. Then, we apply the needed patches to Qmail:

# cd /usr/local/src
# tar zxf netqmail-1.06.tar.gz
# tar zxf qmail_patches.tar.gz
# mv qmail_patches/* netqmail-1.06/
# rmdir ../qmail_patches
# cd netqmail-1.06
# patch < qmail-big-ext-todo.patch
# patch < qmail-big-concurrency.patch
# patch < qmail-doublebounce-trim.patch
# patch < qmail-1.03-dns.patch
# patch < qmail-1.03-mfcheck.4.patch
# patch < qmail-1.03-pop3d-stat.patch
# patch < qmail-bounce.patch
# patch < qmail-bouncecontrol-1.03.patch
# patch < qmail-tarpit.patch
# patch < qmail-badrcptto.patch
# patch < qmail-smtpd-relay-reject.patch
# patch < qmail-accept-5xx.patch
# patch < qmail-nullenvsender.patch

Some of the above patches were modified by me because of some code conflicts. I did not create one big patch for everything since some of you might not want to install a specific patch. If you are interested in what each of the above patches does, here is some info:

  • qmail-big-ext-todo.patch: The exttodo patch addresses a problem known as the silly qmail (queue) problem. This problem is found only on systems with high injection rates. qmail with a big local and remote concurrency could deliver a tremendous amount of messages but normally this can not be achieved because qmail-send becomes a bottleneck on those high volume servers. qmail-send preprocesses all new messages before distributing them for local or remote delivering. In one run qmail-send does one todo run but has the ability to close multiple jobs. Because of this layout qmail-send can not feed all the new available (local/remote) delivery slots and therefore it is not possible to achieve the maximum throughput. This would be a minor problem if one qmail-send run could be done in extreme short time but because of many file system calls (fsync and (un)link) a todo run is expensive and throttles the throughput. The exttodo patch tries to solve the problem by moving the todo routine into an external program. This reduces the run time in qmail-send.
  • qmail-big-concurrency.patch: Allows qmail to use a concurrency greater than 240 (current qmail limit). It has been reported to work well in almost all environments and might be handy if you are expecting high volumes of mail traffic.
  • qmail-doublebounce-trim.patch: I decided to integrate this patch because I got sick of double bounce messages sitting in qmail queue forever. Spammers usually fake the from field with an invalid email address, which results in thousands of bounce messages. This patch allows you to complete discard all double bounce messages to save server load and traffic.
  • qmail-1.03-dns.patch: Christopher Davis's oversize DNS patch -- it makes qmail accept oversized DNS packets. If you do not want some of the legitimate mail to get lost, I would recommend you to use this patch.
  • qmail-1.03-mfcheck.4.patch: I consider this patch mandatory for any qmail installation. A lot of spammers use fake domain names in their messages -- this patch checks if the domain in "from" field exists. If it doesn't, the email simply gets rejected.
  • qmail-1.03-pop3d-stat.patch: This patch changes the number of messages returned in qmail-pop3d's reponse to STAT. The patch makes qmail fully compliant with RFC 1939, which specifies that deleted messages aren't counted in total.
  • qmail-bounce.patch: Allows you to specify the limit for bounce messages in /var/qmail/control/bouncemaxbytes.
  • qmail-bouncecontrol-1.03.patch: Allows you to control the appearance of bounce messages. Very handy if you want to change the default bounce message or add a message in another language.
  • qmail-tarpit.patch: The tarpit patch is targeted towards spammers who try to bomb your mail server with a long list of recipients. It inserts small delays in an smtp session for each recipient in the mail message (after some set number of recipients). This slows down their session, resulting in timeouts in spammer's mail software.
  • qmail-badrcptto.patch: Lets you reject e-mail at the smtp envelope (rcpt) phase, which can produce a considerable bandwidth saving when a lot of e-mail is directed at non-existing users. Instead of receiving the body of the e-mail and then rejecting it in qmail-send, you can reject it before receiving the body. This can be very useful in a setup where you have one qmail box accepting all the e-mail, which then passes it on to another (q)mail box behind it.
  • qmail-smtpd-relay-reject.patch: Russell Nelson's patch to reject relay probes generated by "anti-spammers". These relay probes have '!', '%' and '@' in the local (username) part of the address. The patch detects them and issues a 553 error "we don't relay".
  • qmail-accept-5xx.patch: Adrian Ho's patch to increase qmail-remote's compliance with RFC2821. Some smtp servers are now emitting 5xx responses from the get-go, and mere RFC821 behavior doesn't deal well with them.
  • qmail-nullenvsender.patch: A lot of your spam will be arriving with a null envelope sender. When those spam messages have multiple envelope recipients, they cannot be bounce messages. This patch rejects emails addressed to multiple recipients with a null envelope sender.

Right now qmail is fully patched. All we need to do is install it. Before running make, we'll first create necessary user accounts and groups that qmail needs for running. We will also create a qmail directory /var/qmail. Make sure that you have enough space in that partition.

# mkdir /var/qmail
# cd /usr/local/src/netqmail-1.05/netqmail-1.05
# groupadd -g 5000 nofiles
# groupadd -g 5001 qmail
# useradd -u 5000 -g nofiles -d /var/qmail/alias alias
# useradd -u 5001 -g nofiles -d /var/qmail qmaild
# useradd -u 5002 -g nofiles -d /var/qmail qmaill
# useradd -u 5003 -g nofiles -d /var/qmail qmailp
# useradd -u 5004 -g qmail -d /var/qmail qmailq
# useradd -u 5005 -g qmail -d /var/qmail qmailr
# useradd -u 5006 -g qmail -d /var/qmail qmails

If you have a FreeBSD system, the above won't work. You will have to add groups and users manually into /etc/groups and /etc/master.passwd and then remake the user database by issuing pwd_mkdb -p /etc/master.passwd. Here is what you would have to do under FreeBSD:

# cd /etc
# echo "nofiles:*:5000:" >> group
# echo "qmail:*:5001:" >> group
# echo "alias:*:5000:5000::0:0::/var/qmail/alias:" >> master.passwd
# echo "qmaild:*:5001:5000::0:0::/var/qmail:" >> master.passwd
# echo "qmaill:*:5002:5000::0:0::/var/qmail:" >> master.passwd
# echo "qmailp:*:5003:5000::0:0::/var/qmail:" >> master.passwd
# echo "qmailq:*:5004:5001::0:0::/var/qmail:" >> master.passwd
# echo "qmailr:*:5005:5001::0:0::/var/qmail:" >> master.passwd
# echo "qmails:*:5006:5001::0:0::/var/qmail:" >> master.passwd
# pwd_mkdb -p /etc/master.passwd

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • StumbleUpon
  • Twitter

Pages: 1 2 3 4 5 6

Posted by MegaZ on December 20, 2002.

Guides and Howtos

73 Responses to “Qmail Howto”

  1. rkarim says:

    hey, i wrote a practical step-by-step how-to on qmail… please see the link: "http://119.15.153.9/qmail/qmail-install.html" , i hope some one will require it.

  2. billyduc says:

    I use Evolution for email client.
    I setup for "test" account to send and receive mail
    When I clicked Send / Receive Button. It prompt me

    Unable to connect to POP server myhost.mydomain.com.
    Error Sending password : -ERR authorization failed
    Please enter the POP password for test on host myhost.mydomain.com

    I enter the password for test account……But the error window is open
    Error While Fetching Mail
    Unable to connect to POP server myhost.mydomain.com.
    Error Sending password : Operation now in progress

  3. MegaZ says:

    billyduc,

    Just install Courier IMAP and you will be able to use Squirrelmail or any other web-based mail system. I personally use Horde http://www.horde.org/ and love the functionality.

    Regarding your other issues with telnetting -- the output seems to be normal and the services are responding. Did you try to send an email to your server through an external provider like gmail/yahoo? Did you try to use a client like Outlook to download emails through POP3/IMAP?

    Nasim

  4. billyduc says:

    I followed you through step 17.1 everything work fine but when I telnet to port 15 and 110 …these errors occur
    ===============================================
    telnet 127.0.0.1 25
    Trying 127.0.0.1…
    Connected to localhost (127.0.0.1).
    Escape character is '^]'.
    220 tnway.com ESMTP
    exit
    502 unimplemented (#5.5.1)
    quit
    ======================================================
    telnet 127.0.0.1 110
    Trying 127.0.0.1…
    Connected to localhost (127.0.0.1).
    Escape character is '^]'.
    +OK
    hello
    -ERR authorization first
    exit
    -ERR authorization first
    =============================================

    What wrong with me ? I really need your help
    Thank in advanced

  5. billyduc says:

    can you have an instruction on how to get squirrelmail work together with your tutorial..
    Thank in advanced

  6. Nelson says:

    Nice tutorial. This is only the patch that I haven't encountered a problem.

    I hope you can add a patch such as validrcptto. This is nice patch. However, I'm getting a hunk failed when I'm trying to patch it after patching all the patch on your tutorial. Probably, some code doesn't conform to validrcptto patch. I'm not a C programmer so I'm getting a hard time fixing the problem. Please inform me via my email ntserafica@yahoo.com if you have the patch.

    This could be a great gift this coming christmas :)

  7. Martin F says:

    So what if I want a more minimalistic solution. Basically I have a mail server that only needs to serve one site, and primarily outgoing mail. So no fancy stuff needed like multiple users and auto-responders.

    I would like to have a suite of admin tools, for instance, being able to manually send an email that's been stuck in the queue and watching the remote mail server response, ideally have a php script parse this information.

    Hours on Google have really only given me scripts for the end-user, none for really managing the admin part of qmail.

  8. Carlos says:

    > -- Qmail Patches from http://megaz.arbuz.com

    Where is the patches, i find but…

  9. hugl3 says:

    Nice tutorial. If anyone needs help, you can contact my via email on my website.
    I could do it for free.

  10. Bill says:

    This was helpful. Thank you.

  11. Jorge Reteguin says:

    Hi Nasim:

    Have you tried to use CourierIMAP 4.3.1 (with AuthLib)?
    I would appreciate your comments about it.

    Thanks.

  12. Yuriy says:

    Hi Nazim,

    Sometimes I have an error when sending email(addresses which I used before or new):

    An error occurred while sending mail.The mail server responded: sorry, that domain isn't in my list of allowed rcpthosts(#5.7.1). Please check the message recipients and try again.

    I thought that it something to do with timing out authentication so I have removed 900 from /etc/relay-ctrl/expiry(step 12->Installing Relay-CTRL; pagehttp://megaz.arbuz.com/2002/12/20/qmail-howto/4) but I'm still getting this error.
    I'll appreciate if you could advice on what could be wrong, please.

    Thanks a lot in advance,
    yuriy

  13. Yuriy says:

    Hi Nazim,

    Problem with setting second virtual domain was sorted out. It turned out that one needs to restart qmail server after adding another virtual domain.
    Also I have sorted an issue with 550 error page(I have wrote about it in one of my previous posts).
    With virtual domain .qmail-default file should exist for each user. So solution was pretty simple: copy original .qmail-default to .qmail-USERNAME in /home/email/yourdomain/ folder. Also my /etc/tcp.smtp looks like this:

    127.:allow,RELAYCLIENT="",RBLSMTPD="",QMAILQUEUE="/var/qmail/bin/qmail-queue"
    :allow,QMAILQUEUE="/var/qmail/bin/qmail-scanner-queue.pl",VERIFY=""



Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Spam Protection by WP-SpamFree