Email pipe

Hi all,

If you have a email server on Linux server, you can pipe email to a backend script easily.
This allows you to parse email or control server in email.

Take an example for PHP

echo 'test: "php -q |/your/script.php"' >> /etc/aliases

This command will need php cli support, in Ubuntu, enter

sudo apt-get install php5-cli

And then create a file called script.php start with #!

  1. #!/usr/bin/php
  2. <?php
  3. // read in email from stdin
  4. $fd = fopen("php://stdin", "r");
  5. $email = "";
  6. while (!feof($fd)) {
  7. $email .= fread($fd, 1024);
  8. }
  9. fclose($fd);

The email content will be in $email, you can do whatever you like

If you are thinking of email command, add a line like

  1. exec ($email);

If you are thinking of calling Drush without managing drupal init externally, you can 

  1. exec ("drush your-custom-command " .$email);


Of coz, it needs certain privilege.

Enjoy ~

Keith

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s