| Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-12-2012, 07:07 AM
|
#1
|
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Rep: 
|
Postfix Server should start a script when receiving email
hi.
ive searched long time for a working conclusion on the internet but i dont found anything.
i have a postfix server running with several restrictions. the only thing missing is that when an email arrives the sever a script should be started. for testing im just using a simple php script that writes to a file:
Code:
#!/usr/bin/php
<?php
$file = fopen("/tmp/postfixtest", "a");
fwrite($file, "Script successfully ran at ".date("Y-m-d H:i:s")."\n");
fclose($file);
?>
on the inet i found somthing like that for my master.cf:
Code:
smtp inet n - - - - smtpd
-o content_filter=myhook
...
...
procmail unix - n n - 10 pipe
flags= user=mxr argv=/usr/bin/procmail -a ${user}
but that didnt work.
logfile:
Code:
fatal: /etc/postfix/master.cf: line 118: bad transport type: user=mxr
mxr is the user im sending the mail to.
what am i doing wrong?
|
|
|
|
07-12-2012, 07:14 AM
|
#2
|
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 42,707
|
you need the -o flag before the options are specified
|
|
|
|
07-12-2012, 07:21 AM
|
#3
|
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Original Poster
Rep: 
|
as u can see there is the -o
Quote:
smtp inet n - - - - smtpd
-o content_filter=myhook
|
or do you mean somewhere else?
|
|
|
|
07-12-2012, 07:24 AM
|
#4
|
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 42,707
|
huh? The error is *VERY* clearly saying it's the procmail line that's wrong. What documentation are you following?
|
|
|
|
07-12-2012, 08:16 AM
|
#6
|
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 42,707
|
does the mxr user actually exist as a system user? That's the account that the procmail process will run as, not an email recipient.
|
|
|
|
07-12-2012, 08:26 AM
|
#7
|
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Original Poster
Rep: 
|
yeah it does exist.
i made one more fault. i uncommented the wrong line in my master.cf (the one with the procmail entry) now:
Code:
smtp inet n - - - - smtpd
-o content_filter=myhook
...
...
...
myhook unix - n n - - pipe
flags=F user=mxr argv=/etc/postfix/postfix.php ${sender} ${size} ${recipient}
these are uncommented.
i sent an email again and now the weird part. the log file says "relay=myhook, delay=0.07, delays=0.05/0/0/0.02, dsn=2.0.0, status=sent (delivered via myhook service)"
but theres no new mail and the script dont ran...
Last edited by Rahhh Man; 07-12-2012 at 08:29 AM.
|
|
|
|
07-13-2012, 12:50 AM
|
#8
|
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Original Poster
Rep: 
|
PUSH
has anyone any idea?
|
|
|
|
07-13-2012, 01:38 AM
|
#9
|
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 42,707
|
So if it's a script when a certain user recieves email, then that should be through a conventional procmail setup really. This other thing about a php script firing off would be non=-standard and ugly.
|
|
|
|
07-13-2012, 03:32 PM
|
#10
|
|
Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,364
|
Quote:
Originally Posted by Rahhh Man
PUSH
has anyone any idea?
|
Being a sendmail user, I would create an alias for that user to your script:
Code:
mxr: /etc/postfix/postfix.php
Another possibility is to use ~/.procmailrc to run the script, as already mentioned by acid_kewpie
Regards
|
|
|
|
07-14-2012, 10:47 AM
|
#11
|
|
Member
Registered: Aug 2004
Location: UK
Distribution: Gentoo, OpenBSD, Debian, FreeBSD, RHEL, CentOS
Posts: 65
Rep:
|
Quote:
Originally Posted by Rahhh Man
PUSH
has anyone any idea?
|
Some food for thought.
- Does the mxr user have access to read files under /etc/postfix?
- Is the postfix.php executable?
- Is /usr/bin/php the correct path to your php executable?
- If the content of postfix.php is the same as in your first post - did the /tmp/postfixtest file get updated? Since the code doesn't read the standard input the email will be lost.
- Can the mxr user write to /tmp/postfixtest?
Just to avoid some possible confusion, this is an extract from the pipe(8) man page:
Code:
user=username:groupname
Execute the external command with the user ID and group ID of the specified username. The software refuses to
execute commands with root privileges, or with the privileges of the mail system owner. If groupname is speci‐
fied, the corresponding group ID is used instead of the group ID of username.
So the mxr user is delivering the mail rather than accepting only mail for mxr. In which case your script would be executed for every email that the smtpd daemon receives (if I'm not mistaken). There will be performance implications if the mail server processes a lot of mail.
Other posters have recommended to use procmail (which can do file locking too...) and this is good advice but I can't say I understand the _real_ problem you are trying to solve.
Regards
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:27 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|