invoke php script on incoming mails on postfix

i'm trying to parse all the incoming mails on postfix using a php script. After a lot of research on the irc linode, postfix channels and Google, i came to know that i will have to play with the /etc/aliases file.

I added the line– his: "| /var/www/his/goompare/ml.php" --(ml.php inserts value into my mysql database and his@gotranz.com being the email id) , but nothing happened. After some more research i found out that it could be because i was using a virtual mail box as i was creating accounts by entering values into my MySql database. So i replaced "his" with "vmail" which is the user i created for postfix. Still it doesnt work.

I think i'm almost there, but is getting it wrong somewhere. Please help! :(

8 Replies

Anything interesting in postfix's mail log?

nothing regarding this in the mail log, no errors, nothing.

Hmmm, nothing at all appears in the mail log when you e-mail his@gotranz.com? That probably means your Postfix isn't getting the e-mail at all (or that logging is broken). That's weird.

In your setup, how would you add a "normal" e-mail address under the gotranz.com domain? There's a couple different ways to handle that, and /etc/aliases might not be where it's looking for gotranz.com stuff. (Also, you have run "newaliases", right?)

This worked for me when I had a similar situation.

Create an alias on the virtual domain, in your case it could be something like:

his@gotranz.com hisgotranzcom

The name is not important and you don't even have to create a real mailbox for the user. Then on /etc/aliases create another alias, mapping the "local" hisgotranzcom user to the script:

hisgotranzcom: |/var/www/his/goompare/ml.php

I don't recall if it was absolutely necessary to remove the space between the pipe and the script path.

@hoopycat i add a new user by inserting values into the 'users' table in the Database 'Mail' in my mysql. Ya i did 'newaliases'.

@GrunkaLunka creating a new alias means adding hisgotranzcom to the table users in the Mail DB ??

I'm not entirely sure on how your setup with the database works, since I went the easy way and just went with regular files.

In theory, there must be a way to add two types of email addresses to the database, regular ones with an actual mailbox and others that just forward email to another address. You want to set up one of the latter ones, which will receive mail and forward it to the local user hisgotrazcom.

Hope that helps.

The database method ends up pretty much like a /etc/postfix/virtual file, but in a database instead of a text file, so I think GrunkaLunka's idea will probably work out. :-)

still nt working. i added the alias hisam@gotranz.com hisamgotranzcom to my Forwardings table in my DB. changed /etc/aliases accordingly.

What is bothering me is that nothing ever has appeared in the mail log about /etc/aliases. i seriously doubt that /etc/aliases is nt being checked by postfix wen i recieve mails.

Also i get a failed deliver report, seems the forwarding isnt working..

" This is the mail system at host gotranz.com.

I'm sorry to have to inform you that your message could not

be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can

delete your own text from the attached returned message.

The mail system

<hisgotranzcom@mail.gotranz.com> (expanded from <his@gotranz.com>): mail for

mail.gotranz.com loops back to myself "

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct