david firstname.lastname@example.org writes:
I know Ruby can do a lot of neat stuff, I was just wondering if someone
has found a way to read emails from a gmail account. The reason is I’m
hoping to create a system that a user can email an account with a
command, and Ruby will read it and exacute that command. Any ideas /
Well, this can be done and in fact has been done before many times. In
principal, this is not very different in concept from mail lists which
you to send commands to the list server to subscribe, unsubscribe or get
information on a particular list etc. In fact, back before the web and
systems that used e-mail to initiate some action/command were fairly
However, they soon whent out of vogue as various limitations became
with the growth of the Internet and more malicious activity.
I’d really consider a few things -
- E-Mail is an inherently insecure mode of communication.
- You have no control over who sends messages to the e-mail address.
- Depending on what sort of commands you want executed, you will need
sort of security/authorisation framework, but due to point 1 above, you
never going to have a really secure system.
I believe gmail allows retrieval of mail via imap/pop as well as access
web interface. Therefore, you could retrieve the messages using this
then the problem becomes one of parsing the message to get the command.
this process easier, you can either find an existing ruby library for
mail messages or simply do it yourself (the basic mail message format is
trivial). To make the parsing easier, you could require commands be
tagged or otherwise marked to make it easy to extract.
I’m too much of a ruby newbie to point you to existing libraries you
but I’m sure there are some out there which will do most of the work.
apart from doing this just to see if you can, I can’t see any real
would probably be better off putting effort into something else.
P.S. I actually wrote a system using Tcl some (too many!) years back
e-mail to “move” a software agent from one host to another. Essentially,
agent (a fairly simple Tcl script) wrote its state variables into a file
was fairly well defined in structure, then sent that file to an e-mail
The message was retrieved from the mailbox via pop, stripped of its
and passed to another Tcl script that worked as a loader. The loader
essentially started a local Tcl agent and set its state to be the values
the e-mail message. The new Tcl script then continued execution on that
This was really just a proof of concept relating to software agents and
serialisable objects (a very primitive form - this is early 90s before
other languages had such facilities). I used this very primitive system
perform data searches on groups of servers (network connectivity was a
back then and remote searches could be more expensive). Essentially, you
specify the information you wanted (in a very primitive way), the hosts
wanted to search and the agent would start. It would “send itself” to
host and start searching for data that matched your criteria. any it
would put into one of its state variables. When it finished on that
would send itself to the next host and repeat the process. After doing
with all hosts, it would send itself “home”, where it would pop up a
window (using Tcl/Tk) displaying the results. At the time, I used e-mail
because it was one of the few platform independent communication
other than writing your own server client system at the Tcl level and
had to deal with different hardware issues depending on the platform
course, as the agents were in Tcl, all platforms had to have a Tcl
It was fun, but really was not practicle even back then. Of course, now
are lots of other approaches that could be used, such as the many OO
which have built in support for serialising objects and pushing them
network. Reflection and other mechanisms which are now much more common
provide additional power.