1

I have a project idea in my head that I am considering trying to execute, but this desktop programmer doesn't really know where to begin when it comes to web server development!

I would like to have a script respond when an e-mail is received at an address, which would query a database, make some decision, and then possibly forward this e-mail to another address. I know I can accomplish the actual parsing and database interaction in Perl or PHP (or really any scripting language) if I write the script and put it into my hosted CGI-BIN directory. But beyond there, I'm a little lost.

In summary:

My specific question is: How do I in essence 'hook in' to the mailbox and execute a script when an e-mail is received?

My more general question is: How do I respond to user events beyond just a requesting a URL? If I wanted to run an application for accepting License codes, for example, how would I accomplish that? (listening for messages on an open socket or port, executing actions against a database, etc.)

My (possibly too-broad) question is: What would my next step be in going deeper? What books or resource made it all click, and made you fell like you had the strength of 1000 IT (wo)men?

More about my background/what I already know:

I've never ventured too far in web development, but the world has grown so interconnected, I can't really continue to sit in the dark. I know how to code and script, write PHP/MySQL websites, and I can navigate a *nix machine with some competency.

Have spent the last 5-10 years focused in the C-family of languages. I replaced a crude knowledge of ASP with a crude knownledge of PHP, with very little JavaScript; lots of VBScript and more recently, Python.

Chris
  • 452
  • 3
  • 14

1 Answers1

1

You'll need to poll the POP3/IMAP mail server for messages. PHP has libraries for handling those protocols for you PHP IMAP. The next step is to get that script running. The most rudimentary way of doing that is to execute it as a cron task that checks the mail server and responds to the emails. On the other hand PHP is not necessarily the language for automating background tasks. Perl has those facilities also, as does Python.

Novikov
  • 4,399
  • 3
  • 28
  • 36
  • I found cron tasks today on my server control panel interface, yeah. My impression is that they would then be run on a time interval; there's no way to 'automated' that process so it's run when an event occurs? Or is that asking for too much? – Chris Feb 20 '11 at 02:41
  • Chris, e-mail is relayed from mail server to mail server through a protocol called SMTP. If the destination address resided on your server then you could definitely respond to the event of the e-mail reaching its destination. However because your mail server is not under your control the only options you have are to poll it or implement a long running background task that connects to a mail server though some kind of push protocol. – Novikov Feb 20 '11 at 11:22
  • I understand transmition is done through SMTP, I had just assumed that performing some scripted action in response to an e-mail event was a frequent enough task that there was something I'm missing. What I gather I'd have to do is write/compile/customize/replace the mail-server executable, and replace Apache's configuration to point to the new one. As you said, it's a shared host, so I can't exactly do that. – Chris Feb 20 '11 at 17:01