<p>I want to run a web application on php and mysql, using the CakePHP framework. And to keep the threshold of using the site at a very low place, I want to not use the standard login with username/password. (And I don't want to hassle my users with something like OpenID either. Goes to user type.)</p>

<p>So I'm thinking that the users shall be able to log in by sending an email to login@domain.com with no subject or content required. And they will get, in reply, an email with a link that will log them in (it will contain a hash). Also I will let the users do some actions without even visiting the site at all, just send an email with command@domain.com and the command will be carried out. I will assume that the users and their email providers takes care of their email account security and as such there is no need for it on my site.</p>

<p>Now, how do I go from an email is sent to an account that is not read by humans to there being fired off some script (basically a "dummy browser client" calls an url( and the cakephp will take care of the rest)?</p>

<hr>

<p>I have never used a cron job before, but I do think I understand their purpose or how they generally work. I can not have the script be called by random people visiting the site, as that solution won't work for several reasons. I think I would like to hear more about the possibility of having the script be run as response to an email coming in, if anyone has any input at all on that. If it's run as a cron job it would only check every X minutes and users would get a lag in their response (if i understand it correctly). </p>

<p>Since there will be different email addresses for different commands, like <strong>login</strong>@domain.com and I know what to do and how to do it to based on the sender email, i dont even need the content, subject or any other headers from the email.</p>

<hr>

<p>There is a lot of worry about security of this application, I understand the issues, but without giving away my concept, I dont think it is a big issue for what I am doing. Also about the usability issue, there really isnt any. It's just gonna be login to provide changes on a users profile if/when they need that and one other command. And this is the main email and is very easy to remember and the outset of this whole concept.</p>

[{'answer_id': 46792, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 2, 'selected': False, 'text': '<p>You\'ll need some sort of CronJob/Timer Service that checks the Mailbox regularly and then acts on it. Alternatively, you should check the mailserver if it can run a script when a mail arrives (i.e. see if it\'s possible to put a spamfilter-script in and "abuse" that functionality to call your script instead).</p>\n\n<p>With pure PHP, you\'re mostly out of luck as something needs to trigger the script. On a Pagewith a LOT of traffic, you could have your index.php or whatever do the check, but when no one visits your site for quite some time, then the mail will not be sent, and you have to be careful of "race conditions" when multiple people are accessing the script at the same time.</p>\n\n<p><strong>Edit:</strong> Just keep one usability flaw in mind: People with Multiple PCs and without an e-Mail Client on every one. For example, I use 4 PCs, but only 1 (my main one) has a Mail Client installed, and I use Webmail to check the other ones. Now, logging in and sending a mail through Webmail is not the greatest usability - in order to use YOUR site, I first have to log in to ANOTHER site, compose a mail through the crappy interface most Webmail tools have and wait for answer. Could as well use OpenID there :-)</p>\n'}, {'answer_id': 46794, 'author': 'Mark Biek', 'author_id': 305, 'author_profile': 'https://Stackoverflow.com/users/305', 'pm_score': 4, 'selected': True, 'text': '<p>I have used the <a href="http://www.phpclasses.org/browse/file/3.html" rel="nofollow noreferrer">pop3 php class</a> with great success (there is also a <a href="http://pear.php.net/package/Net_POP3" rel="nofollow noreferrer">Pear POP3 module</a>).</p>\n\n<p>Using the pop3 class looks something like this:</p>\n\n<pre><code>require (\'pop3.php\');\n\n$pop3 = new pop3_class();\n$pop3-&gt;hostname = MAILHOST;\n$pop3-&gt;Open();\n$pop3-&gt;Login(\'myemailaddress@mydomain.com\', \'mypassword\');\n\nforeach($pop3-&gt;ListMessages("","") as $msgidx =&gt; $msgsize)\n{\n    $headers = "";\n    $body = "";\n\n    $pop3-&gt;RetrieveMessage($msgidx, $headers, $body, -1);\n}\n</code></pre>\n\n<p>I use it to monitor a POP3 mailbox which feeds into a database.  </p>\n\n<p>It gets called by a cronjob which uses wget to call the url to my php script.</p>\n\n<pre><code>*/5 * * * * "wget -q --http-user=me --http-passwd=pass \'http://mydomain.com/mail.php\'" &gt;&gt; /dev/null 2&gt;&amp;1\n</code></pre>\n\n<p><strong>Edit</strong></p>\n\n<p>I\'ve been thinking about your need to have users send certain site commands by email.</p>\n\n<p>Wouldn\'t it be easier to have a single address that multiple commands can be sent to rather than having multiple addresses?</p>\n\n<p>I think the security concerns are pretty valid too.  Unless the commands are non-destructive or aren\'t doing anything user-specific, the system will be wide open to anyone who knows how to spoof an email address (which would be everyone :) ).</p>\n'}, {'answer_id': 49556, 'author': 'Pat', 'author_id': 238, 'author_profile': 'https://Stackoverflow.com/users/238', 'pm_score': 2, 'selected': False, 'text': '<p>If your server allows it you can use a <a href="http://activecampaign.com/support/tt/index.php?action=kb&amp;article=145" rel="nofollow noreferrer">.forward</a> file or <a href="http://en.wikipedia.org/wiki/Procmail" rel="nofollow noreferrer">Procmail</a> to start a process (php or anything) when a mail arrives to a certain address.</p>\n'}, {'answer_id': 49584, 'author': 'Kibbee', 'author_id': 1862, 'author_profile': 'https://Stackoverflow.com/users/1862', 'pm_score': 1, 'selected': False, 'text': "<p>You don't want to hassle users with OpenID, but you want them to deal with this email scheme.  Firstly, email can take a long time to go through.  There isn't any guaranteed time that an email will be delivered in.  It's not even guaranteed that the email will get there at all.  I know things usually are quick, but it's not uncommon to take up to 10 minutes for a round trip to be completed. Also, unless you're encrypting the email, the link you are sending back is sent in the open. That means anybody can use that link to log in.  Depending one how secure you want to be, this may or may not be an issue, but it's definitely something to think about.  Using a non-standard login method like this is going to be a lot more work than it is probably worth, and I can't really see any advantages to the whole process.</p>\n"}, {'answer_id': 49600, 'author': 'Marie Fischer', 'author_id': 719, 'author_profile': 'https://Stackoverflow.com/users/719', 'pm_score': 1, 'selected': False, 'text': "<p>I was also thinking using procmail to start some script. There is also formail, which might come in handy to change or extract headers. If you have admin access to the mail server, you could also use /etc/aliases and just pipe to your script.</p>\n\n<p>Besides usability issues, you should really think about security - it's actually quite simple to send email with a fake sender address, so I would not rely on it for anything critical.</p>\n"}, {'answer_id': 49617, 'author': 'erlando', 'author_id': 4192, 'author_profile': 'https://Stackoverflow.com/users/4192', 'pm_score': 0, 'selected': False, 'text': '<p>I would seriously reconsider this approach. E-mail hasn\'t got very high reliability. There\'s all kinds of spamfilters that might intercept e-mails with links thereby rendering the "command" half-finished, not to mention the security risks.</p>\n\n<p>It\'s very easy to spoof the sender-address on an e-mail. You are basically opening up your system to anyone.</p>\n\n<p>Also instead of a username/password combination you\'re suddenly requiring the users to remember a list of commands to put in front of an email-address. It would be better to provide them with a username/password and then giving access to a help page.</p>\n\n<p>In other words the usability and security of this scheme scores very low.</p>\n\n<p>I can\'t really find any advantages to this approach that even comes close to outweighing the massive disadvantages.</p>\n'}, {'answer_id': 55290, 'author': 'bmb', 'author_id': 5298, 'author_profile': 'https://Stackoverflow.com/users/5298', 'pm_score': 1, 'selected': False, 'text': '<p>I agree with all the security concerns.  Your assumption that "the users and their email providers takes care of their email account security" is not correct when it comes to the sender\'s e-mail address.</p>\n\n<p>But since you specifically asked "how do I go from an email is sent to an account that is not read by humans to there being fired off some script", I recommend using procmail to deliver the incoming e-mail to a script you write.  </p>\n\n<p>I would not call a URL.  I would have the script perform the work by reading the message sent in on stdin.  That way, the script is not acessible to anyone on the web site.</p>\n\n<p>To set this up, the e-mail address you provide to your users will have to be associated with a real user\non the system.  In that user\'s home directory, create a file called ".procmailrc"</p>\n\n<p>In that file, add these two lines:</p>\n\n<pre><code>:0 hb:\n| /path/to/program\n</code></pre>\n\n<p>Where /path/to/program is the full path to the script or program for handling\nthe incoming message.  Then create the script with code something like this:</p>\n\n<pre><code>#!/usr/bin/php\n&lt;?php\n\n$fp=fopen(\'php://stdin\',\'r\');\nwhile($line = fgets($fp)) {\n    [do something with each $line of input here]\n}\n\n?&gt;\n</code></pre>\n\n<p>The e-mail message will not remain in the mailbox, so if you want to save or log it, have the script do it.</p>\n\n<p>--<br>\nBruce</p>\n'}, {'answer_id': 76272, 'author': 'Trausti Thor', 'author_id': 6801, 'author_profile': 'https://Stackoverflow.com/users/6801', 'pm_score': 0, 'selected': False, 'text': '<p>One solution to prevent spam, make sure the first line, last line or a specific line contains a certain string, almost like a password, but a full sentence is better.</p>\n\n<p>Only you have the word or words, pretty secure, just remember to delete the mails after use and those that do not have the secret line.</p>\n'}, {'answer_id': 85628, 'author': 'Gaurav', 'author_id': 13492, 'author_profile': 'https://Stackoverflow.com/users/13492', 'pm_score': 0, 'selected': False, 'text': "<p>Apart from the security and usability email delivery can be another problem. Depending on the user's email provider, email delivery can be delayed from a few minutes to few hours.</p>\n"}, {'answer_id': 86272, 'author': 'Rene', 'author_id': 16352, 'author_profile': 'https://Stackoverflow.com/users/16352', 'pm_score': 0, 'selected': False, 'text': '<p>There is a realy nice educational story on <a href="http://thedailywtf.com/Comments/Classic-WTF-The-Complicators-Gloves.aspx" rel="nofollow noreferrer">thedailywtf.com</a> on designing software. The posed question should be solved by a proper design, not by techo-woopla.</p>\n\n<p>Alexander, please read the linked story and think gloves, not email-driven webpage browsing.</p>\n\n<p>PHP is not a <a href="http://www.answers.com/topic/when-all-you-have-is-a-hammer-everything-looks-like-a-nail" rel="nofollow noreferrer">hammer</a>.</p>\n'}]
['https://Stackoverflow.com/questions/46777', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4013/']