There must be many people who'd like to post their status to Twitter from cell-phones. In my case, Twitter hasn't supported the cell-phones provided by Japanese careers yet, or to be exact, Japanese cell-phones don't support International SMS, so I've been forced inconvenience on not to be able to do it. However, it's nonsence that I only wait for them to concider my circumstance. I have to help me for myself.
Today, I found DreamHost, which hosts this blog and other websites of mine, supported piping E-mails into other programs. Great! I went straight to write a tiny script, mail2twitter.rb, which allows me to post my status via e-mail. Then I created a new user to accept the e-mails. Finally, created a file named .forward.postfix right under the user's home directory like this:
"| /home/username/path/to/mail2twitter.rb"
That's all. For more, consult DreamHost Wiki to know how to configure your environment. And I drew upon a script written by ma.la to write this script. Thanks!
Note:
- Don't forget to give the script an executable privilege(e.g.
chmod +x mail2twitter.rb). - Hide the address to accept e-mails from anyone. mail2twitter.rb checks who sends an e-mail by From field of it, but, you know, it's inadequate to save your status from malicious people.
- This way explained here is basically applicable to other environments which support e-mail piping.
#!/usr/bin/ruby
require 'uri'
require 'kconv'
require 'mailread'
require 'net/http'
username = 'username'
password = 'password'
addresses = ['foo@exapmle.com', 'bar@example.com']
mail = Mail.new($stdin)
exit unless addresses.find{|address| mail['From'].index address}
status = URI.escape(Kconv::kconv(mail['Subject'], Kconv::UTF8, Kconv::AUTO))
req = Net::HTTP::Post.new('/statuses/update.json')
req.body = 'status=' + status
req.basic_auth username, password
Net::HTTP.new('twitter.com', 80).start {|http|
http.request req
}
Comments (2)
That's a great idea! I didn't know Dreamhost supported that. I use Dreamhost for my blogs as well.
どうもどうも!
Posted by メイソン・ブラウン | April 16, 2007 8:53 AM
Posted on April 16, 2007 08:53
Thank you for posting a comment! And DreamHost rocks!
Posted by kentaro | April 16, 2007 11:47 PM
Posted on April 16, 2007 23:47