• 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

create mail handler HOW-TO

Pixman59

New Pleskian
Hello, i want to create a mail handler for create a copy of each receive mail, in a folder ( for backup )

i have read this article : http://download1.parallels.com/Ples...9.2-unix-mod-api/index.htm?fileName=38611.htm
and create my handler, add it, and activate it with ./mailmng, but it's never call.

my handler script is inspired by this article : http://serverfault.com/questions/133790/copying-email-with-qmail-and-plesk


If i test my handler with /usr/local/psa/admin/bin/mailmng --check-handler --handler-name=1-backupMails-wp --handler-type=global --hook=before-local

./mailmng respond : not implemented yet

my handler exist, i can view it in the /var/lib/plesk/mail/handlers/handlers.db database

but it's never call.

Thanks for your help.
 
Please post your full Plesk version (OS and arch would be nice too).

Post output of (provided you have the utility; you may post only the line that lists your handler):

# /usr/local/psa/admin/sbin/mail_handlers_control --list

Do you need your handler to be called for all local mail addresses? I suppose you're running QMail, aren't you?
 
Hello,
I'm using plesk on centos server ( 11.5.30 CentOS 5 115130916.13 )

I have test your command line, and all it's ok

Code:
.---.---.-------.--------------------------------------.-----------------.------------------.---------------.
| E | P | prior |               address                |       name      |       type       |     queue     |
|---|---|-------|--------------------------------------|-----------------|------------------|---------------|
|   |   |    10 |                                  all |             spf |           global |  before-queue |
| X |   |    10 |                                  all |     backupMails |           global |  before-local |
| X |   |    10 |                       all-recipients |     check-quota |           global |  before-queue |
'---'---'-------'--------------------------------------'-----------------'------------------'---------------'

After maillog inspection, i have found the source of the error :
"I have erase somes data with xxxx"
Code:
Oct 11 10:27:49 xxxxxxxxxx qmail-local-handlers[24529]: handlers_stderr: Mail handler call failed. Error occured during execv(/xxxxxxxxxx/1-backupMails-wp.sh): Exec format error
Oct 11 10:27:49 xxxxxxxxxx qmail-local-handlers[24529]: handlers_stderr: .

I'ts strange, because my script is really simple :

Note : "context" is an existing directory with root access
Code:
#!/bin/bash
# The email is passed on stdin - grab it to a variable
e=`cat -`

# $1 = context (/xxx/incoming)
# $3 = recipient ([email protected])
# Create /xxx/incoming/[email protected]
mkdir -p $1$3
# Save the email to /xxx/incoming/[email protected]/0123456789.txt
echo "$e" > $1$3/`date +%s%N`.txt

# Echo PASS to stderr
echo 'PASS' >&2

# Echo the email to stdout
echo "$e"

Thanks for your help.
 
From execve(2):

ENOEXEC
An executable is not in a recognized format, is for the wrong architecture, or has some other format error that means it cannot be executed.

I suggest trying with much simpler script first:

#!/bin/bash
echo STOP >&2
exit 1


Make sure script is executable and accessible by popuser group.

This script should prevent any mail from delivery (and you should see appropriate messages in maillog).
 
Actually my script have this chmod :
Code:
-rwxr-xr-x 1 root root

I make the test with more your simple script and post it !
 
the test is good, handler is correctly executed.
I have an error in my script !

The search continue, but it's not a plesk or Qmail problem.
 
I have found the error !

It's really simple!

Mys error is due to a comment ins my script file !

The handler manager call the script using execv()
and execv() can run scripts files ,but the requirement is to include the interopreter in the first line :

Code:
#!/bin/bash

But in my script i have include a comment in the first line.
it's a really newbee error, but now it's work fine !
 
Back
Top