• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

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 ex2@localhost.localdomain admin@example.com Date: Tue, 29 Nov 2016 10:36:41 +0000#012To: my@externaladdress.com, admin@example.com#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: <20161129103641.1718.49054@localhost.localdomain>#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 ex2@localhost.localdomain my@externaladdress.com Date: Tue, 29 Nov 2016 10:36:41 +0000#012To: my@externaladdress.com, admin@example.com#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: <20161129103641.1718.49054@localhost.localdomain>#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] == 'root@localhost.localdomain') 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