From Gentoo Wiki
(Redirected from Netqmail)
Jump to: navigation, search


qmail is a fast, popular Mail Transfer Agent (MTA).


As only one MTA can be installed at the same time on a system, it might be required to deselect an installed MTA. The package manager will report a block when another MTA is still installed. For example, a previously selected mail-mta/ssmtp can be marked as removable with this command:

root #emerge --deselect mail-mta/ssmtp


mail-mta/netqmail has several USE flags that may be desired for certain bigger setups. As this article aims at installing and configuring a basic netqmail setup, adding qmail plugin support with qmail-spp and ucspi-tcp support is necessary.

root #echo "mail-mta/netqmail qmail-spp" >> /etc/portage/package.use
root #echo "sys-apps/ucspi-tcp qmail-spp" >> /etc/portage/package.use
root #emerge --ask netqmail


The default 16 MiB of memory for qmail is a little sparse. Update the memory to 32 MiB to avoid memory related errors.

root #sed -i 's/16000000/32000000/' /var/qmail/control/conf-common
root #emerge --ask --config netqmail

Setting up non-root account for mail

The design of qmail has been completely around the focus of security. To this end, e-mail is never sent to the user root. Select a user on the machine to receive mail that would normally be destined for root. The remainder of this guide will that user as myusername.

FILE /var/qmail/alias/.qmail-rootqmail-root
FILE /var/qmail/alias/.qmail-postmasterqmail-postmaster
FILE /var/qmail/alias/.qmail-mailer-daemonqmail-mailer-daemon

Or to send this email elsewhere, simply put the full address in:

FILE /var/qmail/alias/.qmail-rootqmail-root
FILE /var/qmail/alias/.qmail-postmasterqmail-postmaster
FILE /var/qmail/alias/.qmail-mailer-daemonqmail-mailer-daemon

Fully Qualified Domain Name (FQDN)

Though not entirely related, for an MTA to function properly, it is imperative that its hostname is set up correctly. Under Gentoo /etc/conf.d/hostname and /etc/conf.d/net are the files responsible for this. In this example, the mail server is named foo on the domain example.com.

FILE /etc/conf.d/netSetup domain name
FILE /etc/conf.d/hostnameSetup hostname
Do not use mail.example.com just because it may be externally known as such. Use the actual name of the system.

Verifying that the FQDN is setup properly for the domain.

Files for a 2nd level domain


user $hostname --fqdn
user $cat me
user $cat defaultdomain
user $cat plusdomain
user $cat locals
user $cat rcpthosts

Files for a 3rd level domain

user $cd /var/qmail/control/
user $hostname --fqdn
user $cat me
user $cat defaultdomain
user $cat plusdomain
user $cat locals
user $cat rcpthosts

Creating Properly Signed Certificates

Move to the qmail control directory:

root #cd /var/qmail/control/

Upgrade the Cert Info to create a 2048bit key:

root #sed -i 's/1024/2048/' /var/qmail/control/servercert.cnf

Update the Cert Info with information pertinent to this host. CN is the fully qualified domain name ie. foo.domain.com:

FILE /var/qmail/control/servercert.cnfBe certain this is the correct CN

create the pem files and key:

root #openssl req -new -nodes -out req.pem -config /var/qmail/control/servercert.cnf -keyout /var/qmail/control/servercert.pem

Get the contents of the request pem file:

root #cat /var/qmail/control/req.pem

Send req.pem to a CA(ie godaddy/Starfield, Versign, etc.) to obtain signed_req.pem:

root #cat myserver.domain.com.crt sf_bundle.crt >> servercert.pem
root #awk '/BEGIN PRIVATE KEY/,/END PRIVATE KEY/' servercert.pem > myserver.domain.com.key

Alternatively, obtain a key from Let's_Encrypt

Start qmail and add it to the default run level

Run the init scripts and setup supervisor links for qmail:

root #ln -s /var/qmail/supervise/qmail-send /service/qmail-send
root #ln -s /var/qmail/supervise/qmail-smtpd /service/qmail-smtpd

start and add netqmail to the default run level:

root #/etc/init.d/svscan start
root #rc-update add svscan default


vpopmail will handle virtual domains, adding, deleting mail domains, accounts, storing passwords etc. vpopmail uses mysql in this setup. Please configure MariaDB or MySQL to follow these instructions.

First we need to tell qmail to use vpopmail when checking smtp passwords:

FILE /var/qmail/control/conf-smtpdtell qmail to use vpopmail for auth

Let's install and setup net-mail/vpopmail:

root #echo 'net-mail/vpopmail clearpasswd mysql' >> /etc/portage/package.use
root #emerge --ask vpopmail

Create the vpopmail database:

If the CREATE USER command return a syntax error at "user", then this is an older MySQL system. In that case, append "identified by 'mypassword'" to the GRANT statement before the semicolon.
root #mysql -u root -p
mysql> create database vpopmail;
mysql> create user vpopmail@localhost identified by 'mypassword';
mysql> grant select, insert, update, delete, create, drop on vpopmail.* to vpopmail@localhost;
mysql> flush privileges; 
mysql> quit

Edit /etc/vpopmail.conf and update the mysql password for the vpopmail user:

FILE /etc/vpopmail.confset the vpopmail user password
# Read-only DB
# Write DB


Finally add net-mail/dovecot to talk to the email clients:

root #echo "net-mail/dovecot vpopmail -mysql -pam" >> /etc/portage/package.use
root #emerge --ask dovecot

Add vpopmail UID info to the default dovecot config:

root #echo 'first_valid_uid = 89' >> /etc/dovecot/dovecot.conf
root #echo 'last_valid_uid = 89' >> /etc/dovecot/dovecot.conf

Edit dovecot SSL configs to pass the SSL certificate to email clients when the login to get mail securely:

FILE /etc/dovecot/conf.d/10-ssl.confset the location of the certs
ssl_cert = </var/qmail/control/servercert.pem
ssl_key = </var/qmail/control/myserver.domain.com.key
FILE /etc/dovecot/conf.d/10-auth.confedit the dovecot auth configs
disable_plaintext_auth = no
auth_mechanisms = plain cram-md5

#!include auth-system.conf.ext  comment this out, don't need it
!include auth-vpopmail.conf.ext
FILE /etc/dovecot/conf.d/auth-vpopmail.conf.extcomment out these two vpopmail lines
# [quota_template=<template>] - %q expands to Maildir++ quota
#  args = quota_template=quota_rule=*:backend=%q}}

Start dovecot and add to the default runlevel:

root #/etc/init.d/dovecot start
root #rc-update add dovecot default