Join 3,557 readers in helping fund MetaFilter (Hide)


Communicating with a website via email
March 22, 2009 1:47 PM   Subscribe

I want to send an email to my website, and then have my website do something with the information contained in the body. HELP!

This has the be the hardest thing to search for on Google, as the results always come back with email server stuff. I'm looking for a simple way to email a chunk of text to a dedicated email address on my server, which would then parse the data and store it in a database.

I can handle all the parsing, storing, etc., I just need to know how to communicate with a script via email.
posted by bjork24 to Computers & Internet (8 answers total) 1 user marked this as a favorite
 
A real world example would be sending an email to flickr, and having it automatically upload the picture attachment. I'm sure twitter has something similar.
posted by bjork24 at 1:49 PM on March 22, 2009


is it a linux server?

procmail is the traditional response, but you can also just use /etc/aliases and pipe the script to a command, depending on your local mail transfer agent. This is usually either sendmail or postfix.

In postfix, it's documented on the aliases man page- basically, it's something like:

datastore: |/usr/local/bin/my_data_store_script.pl
posted by jenkinsEar at 1:56 PM on March 22, 2009


You wouldn't even have to use 'your' server, any email account with IMAP or even POP3 (gmail being the most obvious choice) would work. Being a Python coder, Python would be the obvious choice, as pretty much any unix/linux server out there has it installed.

You'll want to look at two libraries built-in to Python: smtplib (for sending) and imaplib (for receiving). The email library works at a higher level and can tie it all together (examples).

To send, you would use smtplib/email to make a message and send it to an email address after connecting to the smtp server of your choice. For receiving, you would connect to your email server with imaplib and search for and download the relevant message. After it's downloaded, you can do anything you want to the data, dump to a text file, put it right into a database, etc.

If you already know code but don't know python specifically, check out Dive Into Python, and of course, the nice tutorials on python.org.
posted by Mach5 at 2:04 PM on March 22, 2009


I would say what you're looking for can be done quite easily using procmail; here is an example. Here is another, more complex one that uses encrypted email to protect the data in question.
posted by PontifexPrimus at 2:05 PM on March 22, 2009


You basically need to install your own mail server software, one that can trigger a script upon receipt of an email, and have your mail forwarded to it.

I would recommend the Apache JAMES Java-based server, which implements the Apache "mailets" script API.

The alternative to using a particular mail server is to write a Windows service or a Linux daemon that automatically polls the mailbox every few minutes and acts on the mail it finds.
posted by XMLicious at 2:06 PM on March 22, 2009


In my cpanel on my website, under mail forwarders, if you click Add Forwarder, there's a "Pipe to Program" option. I put the URL of the script (php or perl or whatever) into that. Basically, it's the GUI version of the answer jenkinsEar just gave you.
posted by JDHarper at 2:08 PM on March 22, 2009


I'm not 100% sure that it's still in the general distribution, but if you're looking to post blog entries via email, that functionality is built into wordpress.

If nothing else, you might be able to look at the source code for Wordpress and figure it out that way.
posted by thecaddy at 2:57 PM on March 22, 2009


A lot of blog engines can handle email-in, which would be automatically posted. I know with flickr, you can definitely hook it to a blog of yours and then do an automatic email-to-blog posting of every photo (last paragraph in the first item here).
posted by mathowie at 8:22 PM on March 22, 2009


« Older Google Maps is great but I won...   |  How can a water logged lawn be... Newer »
This thread is closed to new comments.