validrcptto – a guide to integrate into plesk
Many of our customers will now know that we use several external mail servers aka spamgate to protect our hosting platforms (and our dedicated servers).
To prevent mailbombing from spammers we use John Simpson / JMS’s validrcptto patch for Qmail. This means that a qmail server will only accept email for a published list of email addresses / aliases / redirects based on .qmail files in whatever qmail installation you have set up.
The problem is twofold for our situation, as plesk has no ability to generate a list of email mailnames:
1. The servers we are protecting are remote. Thus qmail on the spamgate servers could never have a list of the emails in any case.
2. Plesk does not wholly conform to .qmail file specifications.
Of course, plesk uses a database to store all information on mailnames. We devised a set of remote mysql queries to pull all mailnames, aliases, redirects from each plesk server, add them to a list and then form a .cdb (flat file database) file that validrcpto could use.
Any customer that has a catchall, which would of course be rendered useless under the above scheme was flagged by another query and an overriding @domain.com was added to the email list. This allows anyemail@domain.com to be delivered versus adhering to a list of mailnames for that particular domain.
Any customer that has their mail.domain.com differing from an array of our own IP addresses i.e. their mail is hosted elsewhere we have that set up as an @domain.com entry so it faithfully delivers.
Queries:
For plesk < 8.2
Catchall Override
SELECT d.displayName FROM Parameters P INNER JOIN DomainServices DS, domains d ON P.id = DS.parameters_id AND d.id = DS.dom_id WHERE value = 'catch' GROUP BY displayName
Mail Hosted elsewhere
SELECT host FROM dns_recs WHERE type = 'A' AND host LIKE 'mail.%' AND val NOT IN (SELECT ip_address FROM IP_Addresses WHERE 1)
Mailnames
SELECT CONCAT(m.mail_name, '@', d.displayName) AS email, d.displayName FROM mail m INNER JOIN domains d ON m.dom_id = d.id WHERE 1 ORDER BY d.displayName
Mail Aliases
SELECT CONCAT(ma.alias, '@', d.displayName) AS email, d.displayName FROM mail_aliases ma INNER JOIN mail m, domains d ON ma.mn_id = m.id AND m.dom_id = d.id WHERE 1 ORDER BY d.displayName
Then it's simply a foreach > $return to provide a list. Per server.
Plesk >= 8.2
The same as above but…
Catchalls
SELECT d.displayName FROM Parameters P INNER JOIN DomainServices DS ON P.id = DS.parameters_id INNER JOIN domains d ON d.id = DS.dom_id WHERE value = ‘catch’ GROUP BY displayName
Aliases
SELECT CONCAT(ma.alias, ‘@’, d.displayName) AS email, d.displayName FROM mail_aliases ma INNER JOIN mail m, domains d ON ma.mn_id = m.id AND m.dom_id = d.id WHERE 1 ORDER BY d.displayName
Of course we need SMTProutes to pass the email to the remote server. It’s simply a domain > mail.domain.com smtproute generated by a simple list of active domains
select host from dns_recs where type = “MX”