====== How to Send Email To Your PDA From the Command Prompt ====== Brendan Kidwell\\ brendan@glump.net 3 October 2008 This tutorial gives you a couple of scripts that allow you to send a short message to your PDA via a proxy on your personal web hosting provider. I created it today because I wanted a quick way to copy a URL from my browser, paste it somewhere, and have it end up on my Blackberry. (The URL in question today happens to be the [[http://www.bbc.co.uk/dna/h2g2/pda/|mobile version of H2G2]], the //[[http://en.wikipedia.org/wiki/The_Hitchhiker's_Guide_to_the_Galaxy|Hitchhiker's Guide to the Galaxy]]// for the real world.) You will need: * A desktop or laptop computer with [[http://www.python.org/|Python]] installed * Access to a web hosting provider (your personal web site) which can run [[http://www.php.net|PHP]] scripts * A PDA that can receive email You might be wondering why I didn't simply build a script to send mnail directly from my desktop via SMTP to my personal email provider. The reason for this is that SMTP from an end-user's computer is problematic. In some places where you take your computer you might be blocked by firewalls. Plus, it can be difficult or impossible to establish SMTP access to most free email providers. On the other hand, I happen to have a personal web host (as do a lot of other people) and scripts that reside there can reliably send email. ===== The Client Script ===== Put this script on your desktop somewhere accessible from your ''$PATH'' environment variable. #!/usr/bin/python # -- Rename this file mailpda.py if you're using Windows. import sys import httplib import urllib webhost = "PUT THE HOSTNAME OF YOUR PERSONAL WEB SPACE HERE" webpath = "/mailpda.php" password = "PUT A PASSWORD HERE" # ---------------------------------------- message = ( # all the command line arguments " ".join(sys.argv[1:]) or # ... or all of the standard input sys.stdin.read() ) headers = { "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain" } conn = httplib.HTTPConnection(webhost) conn.request( "POST", webpath, urllib.urlencode({ "password": password, "message": message }), headers ) response = conn.getresponse() print "Response code: %s %s" % (response.status, response.reason) print response.read() conn.close() It's a good idea to use a tool like [[http://www.adel.nursat.kz/apg/|apg]] to generate a //long//, //random// password. You don't want someone discovering your script and spamming your PDA. ===== The Proxy Script ===== Put this script in the root folder of your personal web space: Done. (The two email addresses specified in the script can be different addresses or the same address. Just make sure ''From'' goes to your PDA.) ===== Usage Examples ===== mailpda "http://www.bbc.co.uk/dna/h2g2/pda/" #Send H2G2 mailpda #interactive input [Type S-Ins to paste from the clipboard, then C-D to end input.] mailpda < some_text_file #send an existing text file useful_command | mailpda #send the output of a command Or... if you only speak Windows: mailpda.py "http://www.bbc.co.uk/dna/h2g2/pda/" #Send H2G2 mailpda.py #interactive input [Type S-Ins to paste from the clipboard, then C-Z to end input.] mailpda.py < some_text_file #send an existing text file useful_command | mailpda.py #send the output of a command