Previous Section  < Day Day Up >  Next Section

Hack 77. Gmail on the Go

You can take it with you ... Gmail on your mobile phone, that is.

Web mail means never having to say you're sorry that you left your laptop at home. While I can't quite fathom it myself—I keep a lot I need beyond basic email on my laptop—there are those that wander the world sans the very core of the mobile office. They're happy to use OP's (other people's). "Where there's a web browser, there's a way" is their credo, and for those who can swing it, more power to them.

Where this falls down for me are the between times: dashing to a meeting without the latest agenda in hand (it's in my email inbox, but my laptop's in my bag and there's no wireless network in sight), meandering a foreign city and wanting to keep in touch with the folks back home but without having to lug around a laptop, and other moments such as these.

The browser experience on even the smartest of smartphones has a way to go. And most folks don't have any more of the Internet on their phones than a basic text-only WAP view of the world Hack #67. While WAP works to some degree, web mail services don't tend to spend much time, if any at all, on providing a WAP interface to your email.

But there's always a workaround ...

Gmail-mobile (; GNU Public License) is a PHP ( application that sits on your web site, between your mobile phone's WAP browser and Gmail, brokering requests on your behalf and returning a mobile-appropriate view of your Gmail mail.

This hack assumes you have an account that allows WAP access to the wild, woolly Web from your mobile phone. Check with your mobile operator about your data plan, and don't forget to ask what you're charged per megabyte, because even the lightest of interactions can add up over time.

You can catch a quick status update, read, and even reply to your Gmail—and there are more features promised.

6.10.1. Installing the Hack

Installing gmail-mobile is a piece of cake; I installed it under both Mac OS X and Linux in a matter of seconds each.

Gmail-mobile assumes you have PHP installed on a web server running on port 80 (the WAP, and indeed web, default). You also need the curl library (, which gmail-mobile uses to talk to Gmail over the Web and the libgmailer ( Hack #80 library, included for your convenience in the gmail-mobile distribution.

Download gmail-mobile ( and unpack the distribution (0.11 at the time of this writing, but yours is sure to be a later version) somewhere under your web server's document root, where the rest of your web site lives (ask your system administrator or service provider if you're not sure where this is):

$ tar -xvzf gmail-mobile-
















$ mv gmail-mobile-0.11 


That last bit renamed the gmail-mobile directory to something a little easier to type on my mobile phone's keypad.

And you're done. No, really, I was surprised too at just how easy it was.

By default, gmail-mobile uses browser cookies to maintain state between requests to Gmail's servers. If you have PHP Session ( installed, you can choose to use it instead of cookies. Just comment out the appropriate line in the config.php file in your newly unpacked gmail-mobile directory. Here, I've left things as they were, using the cookie default:





   /** Session handling method. You must at least choose (uncomment) one. **/


   /**** have PHP Session installed, prefer to use cookie to store session **/

   //$config_session = (GM_USE_PHPSESSION | GM_USE_COOKIE);   

   /**** have PHP Session installed, prefer NOT to use cookie **/

   //$config_session = (GM_USE_PHPSESSION | !GM_USE_COOKIE);   

   /**** do not have PHP Session installed **/

   $config_session = (!GM_USE_PHPSESSION | GM_USE_COOKIE);



6.10.2. Running the Hack

With the easy part out of the way (isn't it wonderful when installation and configuration is the easy part?) you're ready to break out your mobile phone's browser and muddle through typing on that minute keypad.

Before trying this out from your mobile phone (and to remove one variable in case something doesn't work as expected), point your computer's web browser at a URL corresponding to the gmail- mobile directory on your web site—e.g.,

You may actually need to tack /index.php on to that URL, but most PHP-enabled servers know to look for and serve up index.php as a default when no filename is specified and there's no static index.html in sight. The gmail-mobile package includes just such an index.php file.

Your browser will respond in one of two ways. Either it'll serve up the raw WML source delivered by gmail-mobile, as shown in Figure 6-23, or it'll throw up its hands in confusion and prompt you to save the source as a file on your hard drive. If the source (displayed in your browser or saved and opened using something like TextEdit on Mac OS X or Notepad on Windows) looks something like Figure 6-23 and doesn't seem to report any PHP or other errors, you're ready to switch to your mobile phone.

Figure 6-23. Raw Gmail Mobile WAP as viewed through a regular browser

Launch your mobile phone's WAP browser Hack #67 and key in the appropriate URL to reach the gmail-mobile directory on your web site, as above.

After a few moments of churning (WAP is lightweight, but most mobile bandwidth is on the light side too), you should be greeted with a login screen (Figure 6-24, left). Key in your Gmail login ( and password, alter the time zone if you feel so inclined, and click OK. Just where you find OK will vary from phone to phone, WAP browser to WAP browser. I found it under the left soft keyService optionsOK on my Nokia Series 60 phone, as shown in Figure 6-24, right.

Figure 6-24. Log in to Gmail Mobile from your mobile's WAP browser (left) and click OK (right)

A few more moments of churning and you should see a summary view of your Gmail account (Figure 6-25, left). To visit any of the folders, navigate over the appropriate link and select it, much as you would links in a regular browser—albeit with esoteric keystrokes rather than a mouse. Figure 6-25, right, shows my rather empty inbox.

Figure 6-25. Take a gander at a summary of the state of your Gmail (left) and visit your inbox (right)

Visit any message (Figure 6-26, left, shows a sample email message) in any of your mailboxes by selecting its link. Compose a new message by selecting the Compose link; reply using the Reply link at the bottom of a message. Figure 6-26, right, shows the composition window in action.

Figure 6-26. Read (left) and respond to (right) Gmail mail on the go

While you can't (at least, at the time of this writing) create, alter, or delete Gmail labels, you can see what they are (Figure 6-27, left) by following the Labels link on the Summary screen (Figure 6-27, right, shows all of my messages labeled "Peeps."

Figure 6-27. Browse your Gmail labels (left) and visit labeled messages (right)

It's not the spiffy tricked-out Gmail interface that you've come to expect, but it's a great way to take your Gmail with you—and, quite frankly, it's better than some of the mobile email applications that I've come across.

6.10.3. See Also

  • The gmail-mobile project has on its to-do list just about anything you're currently wishing for, including search, archive, delete, forward, label, mark as spam, and working with the Gmail address book Hack #73. Keep an eye on the project page ( for the latest news and distributions.

    If you're new to mobile browsing, you might want to take a gander at [Hack #67] .

    Previous Section  < Day Day Up >  Next Section