I don't know of any Arduino code to do it, but the first thing you'll need to find is an encoder to take whatever format the picture is in, ensure it turns up as a JPEG, PNG, or other file format, then encode that file for transmission by email. A common encoding mechanism is Base 64.
The Internet RFC that covers sending SMTP messages with MIME attachments is RFC 3030 - SMTP Service Extensions for Transmission of Large and Binary MIME Messages
You could trawl through that one and try to interpret it yourself. Alternately you could send an email with an image attachment using your normal mail client and packet-sniff the exchange with the non-SSL mail server. Being able to replay that message would be an ideal starting point. You can "cheat" and simply take the encoded image data, store that on the SD Card, and write your code to assemble the SMTP message using the pre-encoded image. The next step would be writing the code to take the original image and end up with the encoded version.
Encoding files is not as scary as it sounds. Base64 encoding as defined in RFC 4648
is actually quite simple.
I would suggest the following steps:
- Write a function that can send a simple email containing "hello world"
- Write a function that will take a given Base 64 encoded file and wrap it with the appropriate SMTP & MIME leaders/trailers (i.e.: 'your' side of the SMTP conversation) as a script in a third file
- Now simply play the script to the SMTP server, replacing "hello world" with the content of your script
- Finally, write a function to take a given file on the SD card and convert it to Base 64 in a second file, reading a chunk, converting it and writing that chunk to the SD card (you'll want to do this in the smallest sized chunks you possibly can)
This will not handle errors gracefully, but handling SMTP errors gracefully is usually a matter of disconnecting and forgetting the transaction
I guesstimate that a brain-dead implementation of the above will take somewhere in the order of a minute to send a 10kB image, most of which will be transferring data back and forth between the Arduino and the SD Card. A smarter implementation which can generate the SMTP conversation and do Base64 encoding on the fly should manage to send the entire message in a few seconds (limited by how fast you can read the data off the SD Card).
But baby steps. Remember Knuth:
- First, make it work
- Then, make it work right
- Only then, make it work fast
In my brief flirtation with Bing and Google just now, I couldn't find any pointers to a Base64 library for Arduino. If anyone can find one, please mention it in this thread, 'cos I want to do Base64 encoding too
If no such beast exists, that will probably be my homework for the weekend.