Qmail: Error messages returned by the server when receiving emails

After a reinstallation of Plesk, the default mail server was changed from qmail to postfix. After switching back to qmail, it looked like qmail didn’t have a problem with the previously existing mailboxes but when sending emails to an email address hosted on this server a few problems occured.

The first time I sent a test Email, I got the following answer from the server:

553 sorry, that domain isn’t in my list of allowed rcpthosts; no valid cert for gatewaying (#5.7.1)

This basically means I need to add the domain name for this email address to /var/qmail/control/rcpthosts. rcpthosts is configuration file containing a list of domain names (one per line), for which qmail should accept emails. If you send an email to info@mydomain.com and mydomain.com is not in the list, qmail will refuse to accept the email. By default, qmail works as an open relay, i.e. you can contact this mail server and state an email address not hosted on it but on a third server and qmail will accept the email and relay it to the third server. So by default qmail will accept all incoming messages. This is of course not a very good idea. Also if a lot of Spam is relayed like this, your mail server will be penalized. So you need to have an rcpthosts file to make sure that qmail will only accept emails for specific domains hosted on this server.

Another interesting file (not really related to the error message but interesting) is /var/qmail/control/locals. This file is used to configure domains for which emails will be delivered locally. So if you add mydomain.com to this file and then send an email from the server itself to info@mydomain.com then this will directly go to the local queue.

Another relevant file is /var/qmail/control/virtualdomains. It allows to define virtual domains. You can define a user that will receive mail for a given domain. You can also define a 1:1 domain alias in there.

You might also get the following error message:

Sorry. Although I’m listed as a best-preference MX or A for that host, it isn’t in my control/locals file, so I don’t treat it as local. (#5.4.6)

As the message says, you will need to add the mail domain to the /var/qmail/control/locals additionally to the localhost. Also make sure that the fully qualified domain name is entered there and not only the hostname.

If any change doesn’t produce any result, it’s probably that you haven’t restarted qmail or have it reload the configuration.

Reloading the configuration is done with one of the following commands:

/etc/init.d/qmail reload
qmailctl reload
/var/qmail/bin/qmailctl reload
svc -h /service/qmail-send

Basically what it does is send a HUP signal to qmail-send.

To complete restart qmail, use one of the following:

qmailctl restart
/var/qmail/bin/qmailctl restart
/etc/init.d/qmail restart

You can also restart qmail by running these three commands in this order:

svc -d /service/qmail-smtpd
svc -t /service/qmail-send
svc -u /service/qmail-smtpd

If none of those work, try:

/etc/rc.d/qmail stop
/etc/rc.d/qmail start

Sometimes qmail-send needs more time to stop or just doesn’t stop. You can check it with:

ps -ef | grep qmail-send | grep -v grep

If it returns anything, it means qmail-send failed to stop. In this case, you’ll need to kill it before starting it again:

killall -9 qmail-send

You might also need to kill qmail-remote and qmail-local:

killall -9 qmail-remote
killall -9 qmail-local

If you are using Plesk you might find the qmail start/stop script there:

/usr/local/psa/rc.d/qmail restart
/opt/psa/rc.d/qmail restart

Leave a Reply

Your email address will not be published.