• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved Mail-Handler - Called twice, why?

lippoliv

Basic Pleskian
Hey there,
as I do develope an Mail-Handler I wondered why it is executed twice per Mail.
I think I got the reason and now I wonder even more.

Theese are my Mail-Handlers:

Code:
root@v22016081573736335:~# plesk sbin mail_handlers_control --list
.---.---.-------.--------------------------------------.-----------------.------------------.-----------------.
| E | P | prior |               address                |       name      |       type       |      queue      |
|---|---|-------|--------------------------------------|-----------------|------------------|-----------------|
|   |   |    10 |                                  all |             spf |           global |    before-queue |
| X | X |    50 |                                  all |      LWAutomail |           global |    before-local |
| X | X |    50 |                                  all |      LWAutomail |           global | before-sendmail |
| X | X |    50 |                                  all |      LWAutomail |           global |   before-remote |
| X |   |    10 |                       all-recipients |     check-quota |           global |    before-queue |
| X |   |    10 |                       all-recipients |     check-quota |           global | before-sendmail |
'---'---'-------'--------------------------------------'-----------------'------------------'-----------------'

As you can see I hook up "before-local", "before-sendmail" and "before-remote". I think my Mailhandler to executed twice because of "before-local" and "before-sendmail". I wanted to clarify that and read the docs, but I can't find information about "before-sendmail". I decided to hoock that queue because of "check-quota" also does that.

Here the link to the official Hooking Points: http://docs.plesk.com/en-US/12.5/extensions-guide/mail-handlers/hooking-points.71845/

No description about "before-sendmail".

Heres an Mail-Log snippet

Code:
Oct 19 11:51:43 w4 postfix/smtpd[9475]: connect from mout.xyz.de[xyz]
Oct 19 11:51:44 w4 postfix/smtpd[9475]: 31BB03380087: client=mout.xyz.de[xyz]
Oct 19 11:51:44 w4 journal: greylisting filter[11758]: Starting greylisting filter...
Oct 19 11:51:44 w4 /usr/lib64/plesk-9.0/psa-pc-remote[1805]: handlers_stderr: SKIP
Oct 19 11:51:44 w4 /usr/lib64/plesk-9.0/psa-pc-remote[1805]: SKIP during call 'grey' handler
Oct 19 11:51:44 w4 postfix/cleanup[11757]: 31BB03380087: message-id=<[email protected]>
Oct 19 11:51:44 w4 /usr/lib64/plesk-9.0/psa-pc-remote[1805]: handlers_stderr: SKIP
Oct 19 11:51:44 w4 /usr/lib64/plesk-9.0/psa-pc-remote[1805]: SKIP during call 'check-quota' handler
Oct 19 11:51:44 w4 journal: spf filter[11760]: Starting spf filter...
Oct 19 11:51:44 w4 journal: spf filter[11760]: Error code: (2) Could not find a valid SPF record
Oct 19 11:51:44 w4 journal: spf filter[11760]: Failed to query MAIL-FROM: No DNS data for 'zxy.com'.
Oct 19 11:51:44 w4 journal: spf filter[11760]: SPF result: none
Oct 19 11:51:44 w4 journal: spf filter[11760]: SPF status: PASS
Oct 19 11:51:44 w4 /usr/lib64/plesk-9.0/psa-pc-remote[1805]: handlers_stderr: PASS
Oct 19 11:51:44 w4 /usr/lib64/plesk-9.0/psa-pc-remote[1805]: PASS during call 'spf' handler
Oct 19 11:51:44 w4 /usr/lib64/plesk-9.0/psa-pc-remote[1805]: handlers_stderr: LOG LWAutomail PASS
Oct 19 11:51:44 w4 /usr/lib64/plesk-9.0/psa-pc-remote[1805]: LWAutomail PASS
Oct 19 11:51:44 w4 /usr/lib64/plesk-9.0/psa-pc-remote[1805]: handlers_stderr: PASS
Oct 19 11:51:44 w4 /usr/lib64/plesk-9.0/psa-pc-remote[1805]: PASS during call 'LWAutomail' handler
Oct 19 11:51:44 w4 postfix/qmgr[1830]: 31BB03380087: from=<[email protected]>, size=84047, nrcpt=1 (queue active)
Oct 19 11:51:44 w4 postfix-local[11775]: postfix-local: [email protected], [email protected], dirname=/var/qmail/mailnames
Oct 19 11:51:44 w4 spamd[3946]: spamd: connection from localhost [::1]:37282 to port 783, fd 6
Oct 19 11:51:44 w4 spamd[3946]: spamd: using default config for [email protected]: /var/qmail/mailnames/abc.de/info/.spamassassin/user_prefs
Oct 19 11:51:44 w4 postfix/smtpd[9475]: disconnect from mout.xyz.de[xyz]
Oct 19 11:51:44 w4 spamd[3946]: spamd: processing message <[email protected]> for [email protected]:30
Oct 19 11:51:44 w4 spamd[3946]: spf: lookup failed: addr is not a string at /usr/share/perl5/vendor_perl/IO/Socket/IP.pm line 662.
Oct 19 11:51:44 w4 spamd[3946]: spf: lookup failed: addr is not a string at /usr/share/perl5/vendor_perl/IO/Socket/IP.pm line 662.
Oct 19 11:51:44 w4 spamd[3946]: spamd: clean message (0.0/5.0) for [email protected]:30 in 0.1 seconds, 83044 bytes.
Oct 19 11:51:44 w4 spamd[3946]: spamd: result: . 0 - scantime=0.1,size=83044,[email protected],uid=30,required_score=5.0,rhost=localhost,raddr=::1,rport=37282,mid=<[email protected]>,autolearn=ham autolearn_force=no
Oct 19 11:51:44 w4 spamd[16790]: prefork: child states: II
Oct 19 11:51:44 w4 postfix-local[11775]: LWAutomail PASS
Oct 19 11:51:44 w4 postfix/pipe[11774]: 31BB03380087: to=<[email protected]>, relay=plesk_virtual, delay=1.1, delays=0.85/0/0/0.27, dsn=2.0.0, status=sent (delivered via plesk_virtual service)
Oct 19 11:51:44 w4 postfix/qmgr[1830]: 31BB03380087: removed

As you can see my Handler "LWAutomail" seems to be called twice as of "LWAutomail PASS" appears twice. Once in the middle via "psa-pc-remote" and once via "postfix-local"...
 
OK I now just hooked up "before-local" and "before-remote" and added a context ("incomming" for "before-local" and "outgoing" for "before-remote"), but it still got called twice:

Code:
root@v22016081573736335:~# plesk sbin mail_handlers_control --list
.---.---.-------.--------------------------------------.-----------------.------------------.-----------------.
| E | P | prior |               address                |       name      |       type       |      queue      |
|---|---|-------|--------------------------------------|-----------------|------------------|-----------------|
|   |   |    10 |                                  all |             spf |           global |    before-queue |
| X | X |    50 |                                  all |      LWAutomail |           global |    before-local |
| X | X |    50 |                                  all |      LWAutomail |           global |   before-remote |
| X |   |    10 |                       all-recipients |     check-quota |           global |    before-queue |
| X |   |    10 |                       all-recipients |     check-quota |           global | before-sendmail |
'---'---'-------'--------------------------------------'-----------------'------------------'-----------------'

Code:
Oct 20 10:44:25 w4 postfix/smtpd[19076]: connect from mail.x.de[ip]
Oct 20 10:44:26 w4 postfix/smtpd[19076]: 422663380350: client=mail.x.de[ip]
Oct 20 10:44:26 w4 journal: greylisting filter[19854]: Starting greylisting filter...
Oct 20 10:44:26 w4 /usr/lib64/plesk-9.0/psa-pc-remote[3142]: handlers_stderr: SKIP
Oct 20 10:44:26 w4 /usr/lib64/plesk-9.0/psa-pc-remote[3142]: SKIP during call 'grey' handler
Oct 20 10:44:26 w4 postfix/cleanup[18498]: 422663380350: message-id=<[email protected]>
Oct 20 10:44:26 w4 /usr/lib64/plesk-9.0/psa-pc-remote[3142]: handlers_stderr: SKIP
Oct 20 10:44:26 w4 /usr/lib64/plesk-9.0/psa-pc-remote[3142]: SKIP during call 'check-quota' handler
Oct 20 10:44:26 w4 journal: spf filter[19856]: Starting spf filter...
Oct 20 10:44:26 w4 journal: spf filter[19856]: SPF result: pass
Oct 20 10:44:26 w4 journal: spf filter[19856]: SPF status: PASS
Oct 20 10:44:26 w4 /usr/lib64/plesk-9.0/psa-pc-remote[3142]: handlers_stderr: PASS
Oct 20 10:44:26 w4 /usr/lib64/plesk-9.0/psa-pc-remote[3142]: PASS during call 'spf' handler
Oct 20 10:44:26 w4 qmail-queue[19857]: scan: the message(drweb.tmp.3cd8DX) sent by [email protected] to [email protected] is passed
Oct 20 10:44:26 w4 /usr/lib64/plesk-9.0/psa-pc-remote[3142]: handlers_stderr: PASS
Oct 20 10:44:26 w4 /usr/lib64/plesk-9.0/psa-pc-remote[3142]: PASS during call 'drweb' handler
Oct 20 10:44:26 w4 postfix/smtpd[19869]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Oct 20 10:44:26 w4 postfix/smtpd[19869]: connect from ip4d14df69.dynamic.kabel-deutschland.de[ip]
Oct 20 10:44:26 w4 /usr/lib64/plesk-9.0/psa-pc-remote[3142]: handlers_stderr: LOG LWAutomail PASS#012PASS
Oct 20 10:44:26 w4 /usr/lib64/plesk-9.0/psa-pc-remote[3142]: LWAutomail PASS
Oct 20 10:44:26 w4 /usr/lib64/plesk-9.0/psa-pc-remote[3142]: PASS during call 'LWAutomail' handler
Oct 20 10:44:26 w4 postfix/qmgr[3162]: 422663380350: from=<[email protected]>, size=16264, nrcpt=1 (queue active)
Oct 20 10:44:26 w4 postfix-local[19872]: postfix-local: [email protected], [email protected], dirname=/var/qmail/mailnames
Oct 20 10:44:26 w4 spamd[1577]: spamd: connection from localhost [::1]:41984 to port 783, fd 6
Oct 20 10:44:26 w4 spamd[1577]: spamd: using default config for [email protected]: /var/qmail/mailnames/x.de/oliver/.spamassassin/user_prefs
Oct 20 10:44:26 w4 spamd[1577]: spamd: processing message <[email protected]> for [email protected]:30
Oct 20 10:44:26 w4 postfix/smtpd[19076]: disconnect from mail.x.de[ip]
Oct 20 10:44:26 w4 spamd[1577]: spf: lookup failed: addr is not a string at /usr/share/perl5/vendor_perl/IO/Socket/IP.pm line 662.
Oct 20 10:44:26 w4 spamd[1577]: spf: lookup failed: addr is not a string at /usr/share/perl5/vendor_perl/IO/Socket/IP.pm line 662.
Oct 20 10:44:26 w4 spamd[1577]: spamd: clean message (-2.2/3.0) for [email protected]:30 in 0.1 seconds, 16279 bytes.
Oct 20 10:44:26 w4 spamd[1577]: spamd: result: . -2 - BAYES_00,HTML_MESSAGE,RP_MATCHES_RCVD,T_FILL_THIS_FORM_SHORT,T_KAM_HTML_FONT_INVALID scantime=0.1,size=16279,[email protected],uid=30,required_score=3.0,rhost=localhost,raddr=::1,rport=41984,mid=<[email protected]>,bayes=0.000000,autolearn=ham autolearn_force=no
Oct 20 10:44:26 w4 spamd[28204]: prefork: child states: II
Oct 20 10:44:26 w4 postfix-local[19872]: LWAutomail PASS
Oct 20 10:44:26 w4 postfix/pipe[19828]: 422663380350: to=<[email protected]>, relay=plesk_virtual, delay=0.92, delays=0.59/0/0/0.33, dsn=2.0.0, status=sent (delivered via plesk_virtual service)
Oct 20 10:44:26 w4 postfix/qmgr[3162]: 422663380350: removed

Code:
mysql> select sender,receiver,context from mail_checks order by id desc limit 3;
+----------------------------------------------+-------------------------+----------+
| sender                                       | receiver                | context  |
+----------------------------------------------+-------------------------+----------+
| [email protected]                             | [email protected]  | Incoming |
| [email protected]                             | [email protected]  | Outgoing |
+----------------------------------------------+-------------------------+----------+
3 rows in set (0.00 sec)

Did you notice the "context"? Seems that for incomming mails both handleres "before-local" and "before-remote" are called... why?
 
Here's some info on the mail handler queues in Plesk. Note that the information below is actual for Plesk Onyx, although it is also mostly applicable to previous Plesk versions (with some small differences).

The following queues are available:
  1. before-data (0) — handlers are called before DATA in SMTP session is available (obviously, this triggers only within SMTP session);
    1. on QMail invoked from qmail-queue (no real difference from before-queue except these handlers are executed before before-queue ones);
    2. on Postfix invoked from Plesk milter (which is registered in Postfix as smtpd_milters, service name is pc-remote);
  2. before-queue (1) — handlers are called after DATA is available and before mail gets into mail queue (also SMTP session only);
    1. on QMail invoked from qmail-queue;
    2. on Postfix invoked from the Plesk milter;
  3. before-remote (3) — handlers are called before mail leaves this server (though they may be called in other cases as well), triggered for mail sent both via SMTP and sendmail;
    1. on QMail invoked from qmail-remote;
    2. on Postfix this is effectively equivalent to placing a handler both into before-queue and before-sendmail (except these handlers will be executed after handlers in both of these queues);
  4. before-sendmail (4) — handlers are called before mail is actually passed to sendmail (triggers only for mail sent via the sendmail utility);
    1. regardless of MTA handlers are invoked from Plesk sendmail wrapper which is actually called when the sendmail utility is used;
  5. before-local (2) — handlers are called before mail is delivered locally;
    1. on QMail invoked from qmail-local;
    2. on Postfix invoked from virtual_transport (called plesk_virtual, which calls postfix-local Plesk utility).
I think this should be enough to understand the behavior you're getting. Basically in your case, before-remote is called when mail gets into queue, before-local is called before mail is delivered.
 
Thanks for the information. This is what I feared above. As of "before-local" has a usefull amount of more detailed data, I wanted to just react in before-local, or on incomming mails, just in before-remote. Currently I dont see any possibility to act this way!?


Code:
| [email protected] | [email protected] | Incoming | Return-Path: <[email protected]>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on my.mx
X-Spam-Level:
X-Spam-Status: No, score=0.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID,
        HTML_FONT_LOW_CONTRAST,HTML_MESSAGE autolearn=ham autolearn_force=no
        version=3.4.0
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from mail-qk0-f171.google.com (mail-qk0-f171.google.com [ip])
        by my.mx (Postfix) with ESMTPS id 1A04C338004D
        for <[email protected]>; Fri, 21 Oct 2016 15:06:36  0200 (CEST)
X-Processed-By: LWAutomail (184 ms)
Received-SPF: none (no valid SPF record)
Received: by mail-qk0-f171.google.com with SMTP id n189so151532468qke.0
        for <[email protected]>; Fri, 21 Oct 2016 06:06:36 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=domain-com.20150623.gappssmtp.com; s=20150623;
        h=from:to:references:in-reply-to:subject:date:message-id:mime-version
         :thread-index:content-language;
        bh=1jGrjpy8LG7jiU/1JqWkVG1XFA15KAXQR4nmmaXPaJ4=;
        b=XLKu6DlKd9eAVg2ddmaGEdby/CpTnJqpD9vknVD666 gZPoCYMVoWgB96ePBOXrACf
          dTZX05YY2bFg3LV 2Vv4BKRz/iMelHo9rXXOpgwRrshwJ28dlUEOMHADehd qPTUih9
         vuotVPmAJqwKpsaFX0IfuiX IU5h9r24c3djZtC2jRdSam22XWyB9YD3ZGhbyzgVZN7e
         CCu9y9Bea61DQWU0oZ3Hx5zWwkZyJGnPv8VSJNLcbex5FXJjrUtcruDAiAdr4 M9/elE
         GOS6rD5IjLNcq2um8VjzLlqyHHmAKGG70qNsaJfLSkYHvkqkY4YZuYasWJuqalVqStcw
         DKeg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:to:references:in-reply-to:subject:date
         :message-id:mime-version:thread-index:content-language;
        bh=1jGrjpy8LG7jiU/1JqWkVG1XFA15KAXQR4nmmaXPaJ4=;
        b=OKXMctpKZRwaGxGJQgVsTDtyKeBuoNu/i/0Ga8/VJOZpzD4ng7XJyK3EQRx0Zul Xo
          myNxjhO04YKFxqK5peqBL3yVUjxizoQmB81zigWE1k3wGLZoc1d2kVoRkNURB2Rb8Rt
         EqrmUptkoZl3G6Jpq13/sBLmkN 4t9KCFAsHsqfHpNifiL5zBd5s/FCpbn39JA ewOAv
         gBEDREnxUtbhtFCF54S4QxZmXpIpARFsB4DPGhp4GKZv7gnbXSZDJGOtKHc3bXd7MOWN
         aymuXmBOhNHUwF8o2CDKVNKlj WuWR D udg0lgDIurvwNZ41aJ aSe099VLvVEQftKM
         saAg==
X-Gm-Message-State: ABUngvcZbbyDQnLLXRalFKJ6DWzF9BnznBm5Xse/la7xnnOIDSJxiZo3j3GVei05iRERiA==
X-Received: by 10.194.97.69 with SMTP id dy5mr652857wjb.53.1477055195089;
        Fri, 21 Oct 2016 06:06:35 -0700 (PDT)
Received: from GDPC201503 (pool-ip.dynamic.wobline-ip.de. [ip])
        by smtp.googlemail.com with ESMTPSA id uq6sm2809052wjc.37.2016.10.21.06.06.33
        for <[email protected]>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
        Fri, 21 Oct 2016 06:06:34 -0700 (PDT)
From: "sender domain" <[email protected]>
To: "' receiver.'" <[email protected]>
References: <[email protected]> <5809CD24.000009.01492@SERVER>
In-Reply-To: <5809CD24.000009.01492@SERVER>
Subject: xyz
Date: Fri, 21 Oct 2016 15:06:30  0200
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/related;
        boundary="----=_NextPart_000_0151_01D22BAC.B4BB51B0"
X-Mailer: Microsoft Outlook 14.0
Thread-Index: AQJAGhmcir3SBzlIEBfLbKDbgqGkyQKNzXGVn8KOHgA=
Content-Language: de |



| [email protected] | [email protected] | Outgoing | Received-SPF: none (no valid SPF record)
Received: by mail-qk0-f171.google.com with SMTP id n189so151532468qke.0
        for <[email protected]>; Fri, 21 Oct 2016 06:06:36 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=domain-com.20150623.gappssmtp.com; s=20150623;
        h=from:to:references:in-reply-to:subject:date:message-id:mime-version
         :thread-index:content-language;
        bh=1jGrjpy8LG7jiU/1JqWkVG1XFA15KAXQR4nmmaXPaJ4=;
        b=XLKu6DlKd9eAVg2ddmaGEdby/CpTnJqpD9vknVD666 gZPoCYMVoWgB96ePBOXrACf
          dTZX05YY2bFg3LV 2Vv4BKRz/iMelHo9rXXOpgwRrshwJ28dlUEOMHADehd qPTUih9
         vuotVPmAJqwKpsaFX0IfuiX IU5h9r24c3djZtC2jRdSam22XWyB9YD3ZGhbyzgVZN7e
         CCu9y9Bea61DQWU0oZ3Hx5zWwkZyJGnPv8VSJNLcbex5FXJjrUtcruDAiAdr4 M9/elE
         GOS6rD5IjLNcq2um8VjzLlqyHHmAKGG70qNsaJfLSkYHvkqkY4YZuYasWJuqalVqStcw
         DKeg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:to:references:in-reply-to:subject:date
         :message-id:mime-version:thread-index:content-language;
        bh=1jGrjpy8LG7jiU/1JqWkVG1XFA15KAXQR4nmmaXPaJ4=;
        b=OKXMctpKZRwaGxGJQgVsTDtyKeBuoNu/i/0Ga8/VJOZpzD4ng7XJyK3EQRx0Zul Xo
          myNxjhO04YKFxqK5peqBL3yVUjxizoQmB81zigWE1k3wGLZoc1d2kVoRkNURB2Rb8Rt
         EqrmUptkoZl3G6Jpq13/sBLmkN 4t9KCFAsHsqfHpNifiL5zBd5s/FCpbn39JA ewOAv
         gBEDREnxUtbhtFCF54S4QxZmXpIpARFsB4DPGhp4GKZv7gnbXSZDJGOtKHc3bXd7MOWN
         aymuXmBOhNHUwF8o2CDKVNKlj WuWR D udg0lgDIurvwNZ41aJ aSe099VLvVEQftKM
         saAg==
X-Gm-Message-State: ABUngvcZbbyDQnLLXRalFKJ6DWzF9BnznBm5Xse/la7xnnOIDSJxiZo3j3GVei05iRERiA==
X-Received: by 10.194.97.69 with SMTP id dy5mr652857wjb.53.1477055195089;
        Fri, 21 Oct 2016 06:06:35 -0700 (PDT)
Received: from GDPC201503 (pool-ip.dynamic.wobline-ip.de. [ip])
        by smtp.googlemail.com with ESMTPSA id uq6sm2809052wjc.37.2016.10.21.06.06.33
        for <[email protected]>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
        Fri, 21 Oct 2016 06:06:34 -0700 (PDT)
From: "sender domain" <[email protected]>
To: "' receiver.'" <[email protected]>
References: <[email protected]> <5809CD24.000009.01492@SERVER>
In-Reply-To: <5809CD24.000009.01492@SERVER>
Subject: xyz
Date: Fri, 21 Oct 2016 15:06:30  0200
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/related;
        boundary="----=_NextPart_000_0151_01D22BAC.B4BB51B0"
X-Mailer: Microsoft Outlook 14.0
Thread-Index: AQJAGhmcir3SBzlIEBfLbKDbgqGkyQKNzXGVn8KOHgA=
Content-Language: de |
 
Could you please describe your use case in more detail? When do you want your handler to be invoked and what should it do?
 
The general Idea is simple: POST some data to an URL on incoming and outgoing mails.

One of the POST-fields is "context" wich I set on registering mail handlers:
Code:
root@v22016081573736335:~# plesk sbin mail_handlers_control --list
.---.---.-------.--------------------------------------.-----------------.------------------.-----------------.
| E | P | prior |               address                |       name      |       type       |      queue      |
|---|---|-------|--------------------------------------|-----------------|------------------|-----------------|
|   |   |    10 |                                  all |             spf |           global |    before-queue |
| X | X |    50 |                                  all |      LWAutomail |           global |    before-local |
| X | X |    50 |                                  all |      LWAutomail |           global |   before-remote |
| X |   |    10 |                       all-recipients |     check-quota |           global |    before-queue |
| X |   |    10 |                       all-recipients |     check-quota |           global | before-sendmail |
'---'---'-------'--------------------------------------'-----------------'------------------'-----------------'
root@v22016081573736335:~# plesk sbin mail_handlers_control --list --extent
.----------.--------------------------------------.------------------------------.
|   name   |               address                |            context           |
|----------|--------------------------------------|------------------------------|
|      spf |                                  all |                         none |
|----------'--------------------------------------'------------------------------|
|Exec:                                               /opt/psa/handlers/hooks/spf |
|----------.--------------------------------------.------------------------------|
| LWAutomail |                                  all |                     Incoming |
|----------'--------------------------------------'------------------------------|
|Exec:            /opt/psa/admin/plib/modules/LWAutomail/scripts/mail-handler.sh |
|----------.--------------------------------------.------------------------------|
| LWAutomail |                                  all |                     Outgoing |
|----------'--------------------------------------'------------------------------|
|Exec:            /opt/psa/admin/plib/modules/LWAutomail/scripts/mail-handler.sh |
|----------.--------------------------------------.------------------------------|
| check-quota |                       all-recipients |                         none |
|----------'--------------------------------------'------------------------------|
|Exec:                                       /opt/psa/handlers/hooks/check-quota |
|----------.--------------------------------------.------------------------------|
| check-quota |                       all-recipients |                         none |
|----------'--------------------------------------'------------------------------|
|Exec:                                       /opt/psa/handlers/hooks/check-quota |
'----------'--------------------------------------'------------------------------'

The "problem" is, that my Handler is called twice while an mail is incomming but just once on outgoing mails.
The handler should be called once per incomming and once per outgoing mail.
 
It would be really nice if I could finish my implementation. Some help from Plesk team would be great.
 
You may use DKIM as a reference implementation. For example:

Code:
root@a10-52-38-93:~# plesk sbin mail_handlers_control --list
.---.---.-------.--------------------------------------.-----------------.------------------.-----------------.
| E | P | prior |               address                |       name      |       type       |      queue      |
|---|---|-------|--------------------------------------|-----------------|------------------|-----------------|
| X |   |    10 |                                  all | dd52-domainkeys |           global |    before-local |
| X |   |    10 |       test1.a10-52-38-93.qa.plesk.ru | dd51-domainkeys |    sender-domain |   before-remote |
'---'---'-------'--------------------------------------'-----------------'------------------'-----------------'

Again, the exact configuration highly depends on your needs. Please carefully read my first reply for details. Also don't be afraid to experiment to achieve the needed result.

In your example mail handler was called twice for incoming mail because on Postfix before-remote is equivalent to before-queue (and therefore is also called for incoming mails, unless something else like the handler type and address field filter the handler out; in your case type is global and address is all, which means handler is called for any mail passing through). Mail handlers from the before-local queue are only called just before mail delivery (so they trigger only for incoming mail).
 
OK as of it looks that there is no way to manage just incoming or (explicit or) outgoing mails, I used an host-lookup on the senders domain to figure out if its in the local configured ips and I decide that way if I do the extensions work on before-remote or before-local.
 
Back
Top