Find the answer to your Linux question:
Results 1 to 9 of 9
I am trying to find a way to execute a .php file shortly after an email has been received and placed into a specific user's mailbox. I do not need ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    14

    Execute Script Email


    I am trying to find a way to execute a .php file shortly after an email has been received and placed into a specific user's mailbox. I do not need to pipe the email to the php file, I just want the php file to be executed. Currently, I have setup my email server using this guide as a reference (I am running Lenny, not etch, used this as a guide): h_t_t_p://workaround.org/ispmail/etch

    Thanks in advance!
    noop

  2. #2
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    is the mail stored on the system as well as the php page? i use virtual directories on mine

    Code:
    #!/bin/bash
    directory=/var/mail/blah/user/new/
    if [ "$(ls -A $directory)" ]; then
    wget http://www.yourserver.com/my.php
    fi
    you could also throw in something to remove the message, if you weren't actually gonna read it.
    linux user # 503963

  3. #3
    Just Joined!
    Join Date
    Nov 2009
    Posts
    14
    Yes the mail is stored on the system as well as the php script.

    I also have virtual users/mail setup.

    Here is the path to each user's mailbox on my server (domain and use name replaced with actual values from a mySQL database):
    /home/vmail/domain.com/username/Maildir

    Where are you placing that script and how would I set that up to check for a specific user?

    Thank you for helping scathefire,
    noop

  4. #4
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    If its only one one user, just substitute my directory variable in the example to whatever suits you. You should have a 'new' and 'cur' directory within your Maildir, unless its all being stored in MBOX format.

    The script can be placed anywhere. Mine is actually fired off in cron, so I drop this inside /etc/crontab
    Code:
    */1 * * * * root /some/place/mail-check.sh
    linux user # 503963

  5. #5
    Just Joined!
    Join Date
    Nov 2009
    Posts
    14
    Thank you for the help scathefire! I have it working using a cron setup, however do you know much about email piping?

  6. #6
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    i've had more luck getting mail piping to work with qmail that postfix. Most of the time its hit and miss, but in the past I would do the following:

    inside of master.cf add a line that would be something like:
    Code:
    myscript unix - n n - - pipe
    user = postfix argv=/path/to/script ${some arguement} ${another arguement}
    those ${} are variables that postfix knows, usually like original_recipient or something. Not required if you don't need them of course. You can define your own variables as well, like --username or -p or whatever you want to pass to your script.

    You have to add a file, if you don't have it called transport inside /etc/postfix, and the following line:
    Code:
    my.email.address@my.domain.com myscript
    Make sure that postfix is setup to look for said file as well:
    Code:
    main.cf
    ...
    transport_maps = hash:/etc/postfix/transport
    Restart mailman and you should theoretically be good to go, check your maillog for errors. You may have to play around with ownerships and permissions to get it right. Like I said, doing it in qmail is much easier, but qmail is dated from what I can tell (its no longer maintained anyways).
    linux user # 503963

  7. #7
    Just Joined!
    Join Date
    Nov 2009
    Posts
    14
    When I do that, I receive this:
    Feb 20 22:33:15 sandbox postfix/trivial-rewrite[1428]: fatal: open database /etc/postfix/transport.db: No such file or directory
    Feb 20 22:33:16 sandbox postfix/master[1384]: warning: process /usr/lib/postfix/trivial-rewrite pid 1428 exit status 1
    Feb 20 22:33:16 sandbox postfix/master[1384]: warning: /usr/lib/postfix/trivial-rewrite: bad command startup -- throttling
    If I rename the transport file to transport.db then I receive:
    Feb 20 22:42:26 sandbox postfix/master[1702]: daemon started -- version 2.5.5, configuration /etc/postfix
    Feb 20 22:42:26 sandbox postfix/qmgr[1705]: 072D5EC090: from=<myemail@mydomain.com>, size=1456, nrcpt=1 (queue active)
    Feb 20 22:42:26 sandbox postfix/trivial-rewrite[1707]: fatal: open database /etc/postfix/transport.db: Invalid argument
    Feb 20 22:42:27 sandbox postfix/master[1702]: warning: process /usr/lib/postfix/trivial-rewrite pid 1707 exit status 1
    Feb 20 22:42:27 sandbox postfix/master[1702]: warning: /usr/lib/postfix/trivial-rewrite: bad command startup -- throttling
    Here is my master.cf file:
    # maildrop. See the Postfix MAILDROP_README file for details.
    # Also specify in main.cf: maildrop_destination_recipient_limit=1
    #
    maildrop unix - n n - - pipe
    flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
    myscript unix - n n - - pipe
    user=vmail argv=/var/script/test.php
    Currently, I am not sending any arguments to the script, I am just trying to get it to execute. I have given the script executive privileges.

    Thanks helping,
    noop

  8. #8
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    you need to run
    Code:
    postmap transport
    from the /etc/postfix directory everytime you edit that transport file, it has to rebuild that berkley db file.
    linux user # 503963

  9. #9
    Just Joined!
    Join Date
    Nov 2009
    Posts
    14
    Hurray! It works!!!! Thank you very much!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •