• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Issue Mail handlers issues

Anton K.

New Pleskian
We are trying to implement mail handler in before-remote queue. However it is getting fired for all addresses, remote and local. We need either an explaination or information on how to get all locally served mail domains from Plesk.

Please advice,
Anton.

[root@plesk-onyx ~]# plesk sbin mail_handlers_control --list --json
{"handlers": [
{
"queue": "before-queue",
"type": "global",
"enabled": false,
"priority": 10,
"name": "spf",
"address": "all",
"executable": "/usr/local/psa/handlers/hooks/spf",
"context": "none",
"protected": false
},
{
"queue": "before-remote",
"type": "global",
"enabled": true,
"priority": 5,
"name": "my_handler",
"address": "all",
"executable": "/usr/local/bin/my_handler.sh",
"context": "none",
"protected": true
},
{
"queue": "before-queue",
"type": "global",
"enabled": true,
"priority": 10,
"name": "check-quota",
"address": "all-recipients",
"executable": "/usr/local/psa/handlers/hooks/check-quota",
"context": "none",
"protected": false
},
{
"queue": "before-sendmail",
"type": "global",
"enabled": true,
"priority": 10,
"name": "check-quota",
"address": "all-recipients",
"executable": "/usr/local/psa/handlers/hooks/check-quota",
"context": "none",
"protected": false
},
{
"queue": "before-queue",
"type": "global",
"enabled": true,
"priority": 5,
"name": "limit-out",
"address": "all-recipients",
"executable": "/usr/local/psa/handlers/hooks/py-limit-out",
"context": "limit",
"protected": false
},
{
"queue": "before-sendmail",
"type": "global",
"enabled": true,
"priority": 5,
"name": "limit-out",
"address": "all-recipients",
"executable": "/usr/local/psa/handlers/hooks/py-limit-out",
"context": "limit",
"protected": false
}
]}


Nov 29 10:36:41 plesk-onyx xhandler: /usr/local/bin/my_handler.sh none [email protected] [email protected] Date: Tue, 29 Nov 2016 10:36:41 +0000#012To: [email protected], [email protected]#012Subject: test msg#012User-Agent: Heirloom mailx 12.5 7/5/10#012MIME-Version: 1.0#012Content-Type: text/plain; charset=us-ascii#012Content-Transfer-Encoding: 7bit#012X-PPP-Message-ID: <[email protected]>#012X-PPP-Vhost: ex2.com#012#012test#012 PPP_SENDER_USER_ID=10001 LANG=C LC_ALL=C PPP_INSIDE_SENDMAIL=1 LOGNAME=ex2 USER=ex2 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOME=/var/www/vhosts/ex2.com
Nov 29 10:36:41 plesk-onyx xhandler: /usr/local/bin/my_handler.sh none [email protected] [email protected] Date: Tue, 29 Nov 2016 10:36:41 +0000#012To: [email protected], [email protected]#012Subject: test msg#012User-Agent: Heirloom mailx 12.5 7/5/10#012MIME-Version: 1.0#012Content-Type: text/plain; charset=us-ascii#012Content-Transfer-Encoding: 7bit#012X-PPP-Message-ID: <[email protected]>#012X-PPP-Vhost: ex2.com#012#012test#012 PPP_SENDER_USER_ID=10001 LANG=C LC_ALL=C PPP_INSIDE_SENDMAIL=1 LOGNAME=ex2 USER=ex2 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOME=/var/www/vhosts/ex2.com
 
Forgot to mention that example.com is a local domain served by Plesk, all local mail is getting delivered locally to this domain and admin mailbox is present, everything is fine. However mail handler fires for all messages.
 

Thank you for your reply, however I didn't find some info on getting local domains, we are doing some sort of hack like this:

transport_path = '/var/spool/postfix/plesk/sdd_transport_maps.db'
virtual_path = '/var/spool/postfix/plesk/virtual.db'

domains = [Milter.utils.parse_addr( x.strip('\x00') )[1] for x in dbhash.open(self.transport_path)]
virtual = {x.strip('\x00'): y.strip('\x00') for x, y in dbhash.open(self.virtual_path).iteritems()}

self.active_domains = [x for x in domains if ( (virtual.has_key('root@%s' % x) and virtual['root@%s' % x] == '[email protected]') or (virtual.has_key(x) and virtual[x] == "1") ) ]

Is it right or wrong? I don't like it, but it works :)

Maybe you can advise some more elegant way to do this?
 
Placing a mail handler in a given queue should be guided by the use case. Maybe you need before-local queue instead. Unfortunately, I am not aware of yours.

As long as handler type is global for before-remote, it will indeed fire for any mail that goes through Postfix smtpd milters subsystem.

Using virtual.db may be an acceptable solution. Whether using sdd_transport_maps.db is acceptable will depend on your Postfix configuration in Plesk.
 
Placing a mail handler in a given queue should be guided by the use case. Maybe you need before-local queue instead. Unfortunately, I am not aware of yours.

As long as handler type is global for before-remote, it will indeed fire for any mail that goes through Postfix smtpd milters subsystem.

Using virtual.db may be an acceptable solution. Whether using sdd_transport_maps.db is acceptable will depend on your Postfix configuration in Plesk.

Ok, but then can you advice how to get active mail domains? Maybe we could use psa database, as far as I can see there are tables DomainServices and domains... As far as I can see there are no other tables that we should use to do this. Right?
 
Back
Top