Jump to content

Triggering A File On Arrival Of Email


Recommended Posts

Just wondering about my options,

Is there nay way to setup a trigger on an email id, for arrival of email. The moment an email arrives, a particular JavaScript or PHP file can be called and triggered.

Just if it is possible and would not put too much load on the server!

Link to comment
Share on other sites

Go to https://tommy.heliohost.org:2083/frontend/paper_lantern/mail/pops.html and create the email address we're going to use in this tutorial. For this example we'll use admin@rutaj6.heliohost.org

 

Now go to https://tommy.heliohost.org:2083/frontend/paper_lantern/mail/filters/managefilters.html and click "Manage Filters" next to the email address we just created.

 

Click "Create New Filter". Name the filter "Pipe Test". For testing let's set it to trigger whenever the Subject contains the string "Pipe Test". Select "Pipe to a Program". In the box type

|/home/rutaj6/email/email_handler.php
That first character is a pipe which is a vertical line. If you want the email to be delivered to your inbox in addition to piping to your script you can click the + on the right side, and set up Deliver to Folder: Inbox. This way it'll pipe it to your script AND put it in the inbox.

 

Create /home/rutaj6/email/email_handler.php with permissions 755. The first two lines are very important. The first line has to be the shebang which is #! and then the path to the PHP version you want to use. The -q flag suppresses the output of php headers. If you echo any output of any kind in your script it will be emailed back to the sender as an error. This includes headers. The second line has to be <?php There can't be any blank lines or random characters or windows line endings. Any of that stuff will mess it up.

#!/opt/cpanel/ea-php71/root/usr/bin/php-cgi -q
<?php

// listen for incoming emails
$sock = fopen("php://stdin", "r");
$email = "";

// read email into buffer
while (!feof($sock)) {
  $email .= fread($sock, 1024);
}

// close socket
fclose($sock);

// log received email
$file = "/home/rutaj6/email/email.log";
$fh = fopen($file, 'a');
fwrite($fh, "$email\n\n\n");
Create /home/rutaj6/email/email.log with permissions 644.

 

Now send an email to yourself at admin@rutaj6.heliohost.org and make sure "Pipe Test" is in the subject line to trigger the filter.

 

If everything worked it should write your email to /home/rutaj6/email/email.log. From there the sky is the limit. You can process this raw input as much as you want and do whatever.

 

Also, completely unrelated to this tutorial, please be aware that each user is only allowed one account as stated in our Terms of Service. Please delete all accounts in excess of one by going to http://www.heliohost.org/classic/support/scripts/delete Possessing more than one account could result in all of your accounts being suspended. Let us know if you need help consolidating your accounts down into one.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...