Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have no idea about Mail Delivery.

but i need redirect ALL incoming e-mail (*@mydomain.com) into an a php script.

i'm using debian

Exists a simple mail server to do this? (without exim, postfix, etc)

i only need redirect all mail request.

if this is not possible without exim, postfix, etc. how can i do this?

thanks!

share|improve this question
    
What exactly do you mean into a php script? What does the script do? –  HTTP500 Aug 3 '12 at 21:26
    
the php script must receive the mail data (headers, subject and body) –  felix46r Aug 3 '12 at 21:33
    
I would seriously consider your need to have a catch-all email alias. It might seem like a good idea now, but you could end up receive many thousands of spam emails an hour. –  Sirch Apr 10 '13 at 16:39

8 Answers 8

When you say "a PHP script" do you mean a PHP script on a webserver elsewhere, or a PHP script run on the command line locally?

I've done sending the mail to a website elsewhere using exim4 and curl, by creating a custom transport like so:

send_to_site:
  driver = pipe
  command = /usr/bin/curl https://example.com/mail.php --data-urlencode "mail@-"
  user = nobody
  group = nogroup
  return_path_add
  delivery_date_add
  envelope_to_add

If you are using Debian's "split configuration" option, you would create a file in /etc/exim4/conf.d/transport/ with this in it. The command here will pass the entire email (headers and body) to mail.php in the variable $_REQUEST["mail"]. You'll need to have your PHP script handle the headers.

To trigger the transport you'll need to have a router configured that matches whatever email you want to receive and uses the above transport to send it. With split configuration, routers go in /etc/exim4/conf.d/router/. For capturing ALL the mail for a specific domain, I haven't tested this but I think this is right:

catchall_mail:
  driver = accept
  domains = mydomain.com
  transport = send_to_site

Debian numbers the files in the router directory to set the order routers are checked in. The first matching router will be used to handle the email. From my configuration here, you'd probably want to number yours around 450 to go after aliases and before the routers that handle local users like hubusers and procmail.

After adding these files to the transport and router directories, you will need to run update-exim4.conf to have Debian create the configuration file exim actually reads.

share|improve this answer
    
@D.Strout This appears to be the answer you're looking for. Just use your own script and read the email from standard input. –  Michael Hampton Apr 16 '13 at 5:32
    
Where does this config go? Is it by domain? This isn't specific enough for me (or others) to fully understand how to apply it. –  D. Strout Apr 16 '13 at 14:38

You need to set up either a POP3 or (preferably) an IMAP server. Then create your email boxes there as normal. Use the appropriate PHP functions to simulate a mail client and periodically poll the email boxes for new messages.

share|improve this answer

I would use postfix to host a @yourdomain catchall account, then have the script use the catchall account mailbox as the base for your script. The other option would be to do something similar to what this guy did, but only if you would prefer to have the mail piped in instead of reading from a directory.

share|improve this answer

If you do not want to run full smtp server packages like postfix, exim4, then fakeSMTP fit your needs. Following is description from website

fakeSMTP is a PHP script written to act like any traditional postfix SMTP server. Used in conjunction with inted, the script is called when a mail client connects to port 25 on the server.

This script does not actually send any emails (although this could theoretically be combined with sendmail if one wanted to). It also does not contain any authorization functionality, and thus acts solely as a badly configured open SMTP relay. I wrote it to create a honeypot for spammers as well as for testing & proof of concept.

fakeSMTP.php can be download from the link provided. The modify /etc/inetd.conf as follow

smtp   stream    tcp    nowait    root    /path/to/fakeSMTP.php

Basically all incoming smtp connection will be handled by fakeSMTP.php. You should incorporate your script into fakeSMTP.php. Base on the following example

$hp = new fakeSMTP;
$hp->serverHello = 'axllent.org ESMTP Postfix'; // Server identity (optional)
$hp->logFile = '/tmp/emails.log'); // Log the transaction files (optional)
$hp->receive();
if (!$hp->mail['rawEmail']) exit; // Script failed to receive a complete transaction
/* The script returns all the mail parts which you can process in $hp->mail(array) - read source for all details */

Your script should make use of $hp->mail(array) for email processing.

I didn't look at the code but you may have to modify it to only accept email of your domain.

As Sirch mention in comment, you may receive huge volume of spam mail, as this script/library do not incorporate RBL, address checking nor amavis/spamassassin. It maybe a bit of work if you are going to incorporate them in your own script.

If you end up decided to use postfix, for RBL, amavis/spamassassin integration, you can follow the answer in HERE.

share|improve this answer

I know you can do something like this with hypermail, but that is written in perl. Not sure about a php implementation.

share|improve this answer

Not sure I understood correctly what you want to do but why don't you simply receive the mails using the mail server you prefer and make your PHP script parse the mailbox(es) automatically (using CRON possibly) looking for new mails, picking the data you need and deleting the mails if you don't need them anymore?

share|improve this answer

I did it with Postfix and virtual alias domains. In main.cf:

virtual_alias_domains = domain.name #Make sure this does _not_ appear in mydestination
virtual_alias_maps = hash:/etc/postfix/virtual

In /etc/postfix/virtual:

@domain.name    anything@localhost

In /etc/aliases:

anything:    "|/path/to/script.php"

Once the files are edited, run postmap /etc/postfix/virtual, newaliases, and service postfix reload to finalize all the new configs. Also, be sure to chmod +x the PHP script and have a PHP hashbang at the top.

share|improve this answer
    
I asked a similar question a while ago that I answered using an equivalent Sendmail config. However, Sendmail didn't seem to be working on a new server I was configuring, hence why I dug up this question and put a bounty on it. However, once again, I found the answer. –  D. Strout Apr 16 '13 at 5:21
    
The original answer would have worked just fine, if you'd simply inserted your own script instead of /usr/bin/curl. –  Michael Hampton Apr 16 '13 at 5:35
    
I thought you don't want to use email package. –  John Siu Apr 16 '13 at 11:47
    
@JohnSiu Like the original asker, I was willing to use an e-mail package if it was needed. And when you consider that fakeSMTP throws all mail at the script, rather than just by domain, it does not work for me. –  D. Strout Apr 16 '13 at 14:40

The most simple solution (without extra software) i have seen so far is using IMAP PHP extension to access (by IMAP) your mailbox.

You can find info on the current documentation for IMAP extension here: http://php.net/manual/en/ref.imap.php

Then, just configure crontab to run the script in the desired period.

share|improve this answer
    
Welcome to Server Fault! Generally we like answers on the site to be able to stand on their own - Links are great, but if that link ever breaks the answer should have enough information to still be helpful. Please consider editing your answer to include more detail. See the FAQ for more info. –  slm Apr 16 '13 at 11:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.