LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
LinkBack Search this Thread
Old 07-12-2012, 07:07 AM   #1
Rahhh Man
LQ Newbie
 
Registered: Jul 2012
Posts: 5

Rep: Reputation: Disabled
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?
 
Old 07-12-2012, 07:14 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 42,707

Rep: Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753
you need the -o flag before the options are specified
 
Old 07-12-2012, 07:21 AM   #3
Rahhh Man
LQ Newbie
 
Registered: Jul 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
as u can see there is the -o
Quote:
smtp inet n - - - - smtpd
-o content_filter=myhook
or do you mean somewhere else?
 
Old 07-12-2012, 07:24 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 42,707

Rep: Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753
huh? The error is *VERY* clearly saying it's the procmail line that's wrong. What documentation are you following?
 
Old 07-12-2012, 07:29 AM   #5
Rahhh Man
LQ Newbie
 
Registered: Jul 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
i used a bit of that : http://www.linuxforums.org/forum/pro...hp-script.html

and that: http://blog.thecodingmachine.com/con...-receives-mail

second one is what i used in this thread


ahh sry i copied the wrong line... thats the right one:
Code:
myhook unix    -       n       n       -       -       pipe
       flags=F user=mxr argv=/etc/postfix/postfix.php ${sender} ${size} ${recipient}

anyway i dont know what im doing wrong...

Last edited by Rahhh Man; 07-12-2012 at 07:43 AM.
 
Old 07-12-2012, 08:16 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 42,707

Rep: Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753
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.
 
Old 07-12-2012, 08:26 AM   #7
Rahhh Man
LQ Newbie
 
Registered: Jul 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
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.
 
Old 07-13-2012, 12:50 AM   #8
Rahhh Man
LQ Newbie
 
Registered: Jul 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
PUSH

has anyone any idea?
 
Old 07-13-2012, 01:38 AM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 42,707

Rep: Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753
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.
 
Old 07-13-2012, 03:32 PM   #10
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,364

Rep: Reputation: 1189Reputation: 1189Reputation: 1189Reputation: 1189Reputation: 1189Reputation: 1189Reputation: 1189Reputation: 1189Reputation: 1189
Quote:
Originally Posted by Rahhh Man View Post
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
 
Old 07-14-2012, 10:47 AM   #11
whizzit
Member
 
Registered: Aug 2004
Location: UK
Distribution: Gentoo, OpenBSD, Debian, FreeBSD, RHEL, CentOS
Posts: 65

Rep: Reputation: 24
Quote:
Originally Posted by Rahhh Man View Post
PUSH

has anyone any idea?
Some food for thought.
  1. Does the mxr user have access to read files under /etc/postfix?
  2. Is the postfix.php executable?
  3. Is /usr/bin/php the correct path to your php executable?
  4. 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.
  5. 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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
POSTFIX - receiving outside email restriction cheesewizz Linux - Newbie 11 06-17-2011 07:32 AM
postfix not receiving email from the outside world zeos386sx Linux - Server 8 05-10-2010 02:29 PM
postfix not receiving email from outside tonyl Linux - Server 2 07-27-2009 06:57 AM
Postfix,Enforce_TLS, and Receiving Email fortezza Linux - Software 0 08-06-2005 11:07 PM
Problems receiving email via postfix ryedunn Linux - General 5 01-01-2005 07:55 PM


All times are GMT -5. The time now is 02:27 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration