Mobile Me(dia)

Shawn Van Every Shawn.Van.Every@nyu.edu
Spring 2008
H79.2690.1

Week 1 - SMS/MMS to Email

SMS

SMS or Short Message Service is a protocol for sending short messages from mobile phones to other mobile phones. Text messaging or texting is a very popular activity worldwide, coming in only second in usage to voice calling. Approximately 50% of users worldwide have used SMS.

Due to the popularity of SMS and people's comfort with it and the fact that it enjoys a very high level of interoperability between carriers, it has been used in a variety of contexts beyond individuals messaging each-other.

Interactive Television - Voting on American Idol
Location based advertising
Daily messaging services
Microblogging - Twitter

More about SMS: Wikipedia: Short message service

SMS to Email

Although it is very costly to get a shortcode (a unique SMS only number) in the US, the carriers here have implemented the ability for SMS messages to be sent to an email address.

Exploiting those capabilities for our purposes is pretty straight forward.

I put together a script in PHP which can be setup to automatically receive an email and take action on that email. The version below which we will go over receives a message and then responds with an email back to the same address.

Download it here: PHP Mail Popper

Once you download this script to your desktop (and extract it) you should have a folder called "php_popper". Inside this folder there should be a file called "parseMailScript.php". You should open this file up in a text editor of your choice (TextWrangler on the Mac is a good choice, TextPad on Windows another good choice).

Once open, look in the script for the section that starts with this:
        	/* User Configurable Variables */
        
Below this there are variables that need to be changed in order for this script to receive your email and parse it. You should setup an email address specifically for use with this script rather than reuse an existing address. This script takes action on any email that arrives in the account and therefore you don't want it mixing with other email that you may need or not want deleted.

The script is setup to work with POP3 mail servers. Gmail uses a slightly different protocol than most normal POP3 servers and requires the "ssl://" in front of the hostname variable. Also, in order for Gmail POP3 to work, you need to enable it on your Gmail account (Settings, Forwarding and POP/IMAP, Enable POP for mail that arrives from now on).

If you are using a mail server other than Gmail, you should put those settings in the variables under this line: // Normal POP settings Be sure to comment out the Gmail specific settings and uncomment the settings that you just made:
	/* User Configurable Variables */

	// Gmail Settings
	//$mailbox_username = "xxx@gmail.com";
	//$mailbox_password = "xxx";
	//$mailbox_hostname = "ssl://pop.gmail.com";
	//$mailbox_port = 995; // SSL
	
	// Normal POP settings
	$mailbox_username = "xxx@xxx.com"; // CHANGE THIS LINE TO YOUR MAIL SERVER USERNAME
	$mailbox_password = "xxx";  // CHANGE THIS LINE TO YOUR MAIL SERVER PASSWORD
	$mailbox_hostname = "mail.xxx.com"; // CHANGE THIS LINE TO YOUR MAIL SERVER NAME
	$mailbox_port = 110; // Default        
        
The next lines that you will need to change are the next three variables, $temp_folder, $attachment_output_folder and $attachment_output_folder_relative.

The first two expect the full path to the folder on the server. In the zip file and therefore in the folder on your desktop there are folders pre-created for these purposes. You are free to use those or to create your own folder on the server.

If you are using ITPs webserver for hosting this script, your variables would look something like this:
        
	$temp_folder = "/home/sve204/public_html/mobilemedia/php_popper/tmp/";
	$attachment_output_folder = "/home/sve204/public_html/mobilemedia/php_popper/posts/";
	$attachment_output_folder_relative = "http://itp.nyu.edu/~sve204/mobilemedia/php_popper/posts/";
		
The next step is to upload the contents of the entire directory up to the server. You should use an SFTP program like Fetch on the Mac or WinSCP on the PC. You can download both of these applications for free from ITS here

Once these files are uploaded, you should log into the server using SSH. On the Mac you can do this by opening up Terminal (Applications, Utilities) and typing "ssh net-id@itp.nyu.edu" and on windows you can use one of the SSH software options made available by ITS.

Once connected, you will want to issue the following commands:
[sve204@itp ~]$ cd public_html/mobilemedia/php_popper
[sve204@itp php_popper]$ chmod 700 parseMailScript.php 
[sve204@itp php_popper]$ ./parseMailScript.php         
        
Here is a rundown: The "cd" command stands for change directory. The "chmod 700" command means make the parseMailScript.php file "read, write and execute" by you (the owner) and the "./" command means run the script.

Webmonkey has a good tutorial/article on Unix commands: Enough Unix for Your Resume as well as a nifty Unix Reference Guide.

Once you issue the command to execute the script, you should see some output like this:
Connected to ssl://pop.gmail.com
Message number: 1
from: mfargo gmail.com
Message number: 2
from: angibabez gmail.com
Message number: 3
from: newnetherland gmail.com        
        
That's it.. Now you are receiving messages into the script. Next week we will look into running this script automatically as well as doing something with those messages..