Published: |
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 mobile version of H2G2, the Hitchhiker's Guide to the Galaxy for the real world.)
You will need:
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.
Put this script on your desktop somewhere accessible from your $PATH
environment variable.
mailpda
#!/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 apg to generate a long, random password. You don't want someone discovering your script and spamming your PDA.
Put this script in the root folder of your personal web space:
mailpda.php
<?php
$recipient = "PUT YOUR PDA'S EMAIL ADDRESS HERE";
$from = "PUT YOUR PERSONAL EMAIL ADDRESS HERE";
$password = "PUT A PASSWORD HERE";
if($_REQUEST['password'] != $password) die("Bad password.");
$header = <<<EOT
From: $from
EOT;
$subject = "";
$mail_body = $_REQUEST['message'];
mail($recipient, $subject, $mail_body, $header);
?>
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.)
mailpda "http://www.bbc.co.uk/dna/h2g2/pda/" #Send H2G2
mailpda #interactive input
[Type Shift+Ins to paste from the clipboard, then Ctrl+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 Shift+Ins to paste from the clipboard, then Ctrl+Z to end input.]
mailpda.py < some_text_file #send an existing text file
useful_command | mailpda.py #send the output of a command
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
Reader-contributed comments on Glump.net are owned by their original authors, who reserve all rights.
Comments rules:
Comments