Thursday, January 19, 2006
« Intellisense for SQL Query Analyzer | Main | XBOX 360 & Online Retailer Extortion - S... »

 

When I snap a picture from my phone, with an extra click or two, I can send it to any email address I want.

I've seen camera blog sites, and thought it would be cool to do my own version. So I'm making this C# .net code available to you all, play with it, improve it, add it to your site. If you implement it, let me know I'd like to see!

Thanks to Scott Hanselman, who gave me the idea to use threads within .NET to accomplish some of the work. I was doing this before with a scheduled webservice that ran once every 15 minutes. While this worked fine, it was a pain to wait 15 minutes for a picture to be posted. It was also kind of lame because not all web hosts have the ability to schedule a web service. Using threading within .NET, when the web application starts, a thread is invoked to do the image checks to an email address you specify. The frequency that the thread starts and stops is also configurable.

Once the initial version of this was created (some time ago) I realized a few things. Initially I had set it up with essentially no security. All someone had to know was the address that I sent images to, and they could post an image to my site. I then added a check to make sure it was coming from my phone's address at least. So someone that wanted to post an image would have to know several things, a.>the address to post messages to, b.>your phone's address, and c.>that you even did this on the web site to begin with. After more consideration I added the ability to turn on one more level of security, a pin code. So if configured in the web.config your sms message must contain a pin that matches a value in the web.config.

Keep in mind that this was developed rather quickly, and there is definite room for improvement. It is currently working with Cingular phone service. I'm guessing that different providers handle messages differently, if there is enough demand, I'm willing to build processing models around the different providers. For instance, cingular's text is added to the message as an attachment, which I thought was odd.

The file included in this post is a C#, .NET 1.1 project, configured to work on Cingular (maybe others) celluar SMS service. The zip file contains the .NET Solution, respective dlls, and two sample images. I have the latest image control on the front page of my site, and it points to the camera blog page.

So here's how it goes:

  • You snap a picture w/ your camera phone.
  • You send the picture via SMS message to an email addrees that's on an POP3 compliant mail server
  • Your web application is always running and checking this address
    • The thread starts the check
    • It logs into the mail account
    • It finds a message from your cellular address
    • It finds an image attachment
    • If pin check is on, it determines if the pin in the message matches your pin setting
  • It posts the picture to your site
  • It deletes the mail message
  • The thread sleeps until time passes and it starts all over again.

On the web site:

 I have included one page of this project called default.aspx that includes:

  • A 'latest' image image control - this user control picks the latest image from directory where they're being stored.
  • The image blogger control that pages the images in a dataset, and allows users to page through them.


web.config settings are documented pretty well. contact me if you have questions.

Feature enhancements:

  • add ability to add text captions and display them w/ the picture, stripping out pin of course.
  • Ideas?

View the latest image control and the image blogger control in action.

Some basic installation instructions and files for download can be found here.