Wordpress + Gmail mobile blogging

Update 10/20/06: I no longer maintain these files, so plan to use them at your own risk.

While Wordpress’ email blogging feature is nice and handy, it unfortunately doesn’t work with secure pop3 access, which is ideally how you access your account. This means anyone wanting to use their Gmail accounts, couldn’t. John Blade’s modifications, while very helpful, also didn’t remedy this issue[1]. So I spent the weekend hacking together a fix. If you want to use a Gmail account for posting to your Wordpress blog, download wp-gmail.phps and class_mbox.phps. This has only been tested for Gmail accounts, so your mileage may vary with other secure pop accounts. Also, as noted in the two files’ comments, Gmail seems to do some funky backend syncing stuff between their pop server and whatever servers a browser accesses (either that, or php’s imap_ functions are buggy ;). So, only un-touched emails will be downloaded, and old emails can’t be deleted through the imap_ calls (do people moblog more than 1GB of data?!)

Since my main moblogging tool will be my new schnazzy DoCoMo phone, support for Japanese characters was paramount. Luckily the imap_ library supports international charsets well, so I’ve written the mbox class to convert everything to UTF-8. This also means other polyglot users out there should be able to use this with no problem. Just remember that your Wordpress should use the UTF-8 character set if doesn’t already.

To install:

  • Place the two files in your root weblog directory (where your wp-config.php exists)
  • Fill in your Gmail account info (under Options->Writing)
  • Test it out by sending an email to the account, then directly running wp-gmail.php through your browser
  • If all is good, setup a crontab (see here for details. As an example, I have mine set to run every ten minutes with: 0,10,20,30,40,50 * * * * curl -sf http://…./wp-gmail.php)

Note for OSX users: Some posts out there say to use “GET http://…” in the crontab; you’ll find that OSX doesn’t come with GET, so I recommend using curl; the “-sf” switch makes it silent (i.e., no progress meter), and to not send failure messages; otherwise, you’ll get emails sent to your user account.

A few other things to note:

  • The original wp-mail.php supported non-image-file attachments, but I haven’t had much time to integrate that in this version (I can’t send anything other than images from my phone anyways…).
  • Skeleton code for thumbnails is scattered throughout wp-gmail.php, but it’s commented out as I didn’t have a need for it. Check it out if thumbnail support interests you.

Be sure to skim through the code before using it; I’ve put in comments throughout that I may have missed mentioning in this post.

And of course, I give no guarantee on its functionality. If you have questions, feel free to ask in the comments.

Enjoy.

[1] the PEAR module included with John’s package probably supports secure pop3 access, but using the php imap_ modules will allow support for other email-access protocols (notably IMAP), not to mention the extensive charset and conversion functions built into the library.

Update 4/17/2005: If you are getting errors related to iconv() or imap_…(), you need to make sure you have the appropriate php version and/or packages installed. A simple Google search will help you find out which ones are necessary for the missing function call.

Digg! delicious
Posted on Monday, March 7th, 2005 at 1:40 am and filed under Internet, diary, geekery. Subscribe to RSS 2.0. Skip to the end and leave a comment. Pinging disabled.

29 Responses to “Wordpress + Gmail mobile blogging”

  1. Ben

    Everything seems to be working, once I figured out that you have to copy the text into a .php file, except for one thing.
    On line 106, you’re missing a paren:
    $post_date = date(’Y-m-d H:i:s’, time($ddate); // + $time_difference);
    should be
    $post_date = date(’Y-m-d H:i:s’, time($ddate)); // + $time_difference);

    It gives a syntax error as is.

  2. matt

    ah, you’re right; thanks Ben. I noticed I was having time zone issues after going live with the final implementation, so I cut out the time_difference factor but forgot to update the download version. And you’re right you need to change the .phps to .php to get it running. It’s set as .phps so that the server doesn’t render the code before sending you the data (otherwise, you wouldn’t be able to see the code! :).

    Glad you found it useful!

  3. Rob

    Hello
    I tried running your wp-gmail.php file but I keep getting this error
    Fatal error: Call to undefined function: imap_open()

    Any idea why I am getting this? I checked my apache2.conf and I am loading the mod_imap.so file.

    Any help would be nice.
    Thanks
    Rob

  4. Ray

    It has to be configured as a php module. Run phpinfo() to see if it is.

  5. Clay

    Hmm… When I follow the instructions, it claims that 1 message is received, but then it given the following error:

    Fatal error: Call to undefined function: iconv() in /home3/…/class_mbox.php on line 103

    Any ideas?

  6. danial

    I am recieving the same “Call to undefine function imap_open()” error when loading wp-gmail.php Help needed!

  7. Dan

    It isn’t working for me….wp-gmail.php just gives me the busy loading icon in firefox…

    Maybe I am typing in the servers wrong? How should it be setup in WP for mail server, port, user, password?

    thanks!

  8. Dan

    Found it out…

    use pop.gmail.com and server 995.

    you MUST enable pop access in the gmail account settings.

  9. Dan

    HELP!

    When I send email from one email account, everything posts fine.

    When I sent email from a different email account, it only posts the subject field and not the message.

    Does it matter if I am sending from an .mil account?

    Thanks

  10. Dan

    Follow up -

    the errors was:

    Notice: Undefined index: metakeyselect in /www/p/pilotoftheca/htdocs/wp-admin/admin-functions.php on line 378

    Notice: Undefined index: metakeyinput in /www/p/pilotoftheca/htdocs/wp-admin/admin-functions.php on line 379

    Notice: Undefined index: metavalue in /www/p/pilotoftheca/htdocs/wp-admin/admin-functions.php on line 380

  11. Dan

    Help!

    If I send an email from my AOL account to the gmail account, everything works fine.

    If I send an email from my military (af.mil) account to the gmail account, wp-gmail.php posts the subject, date, and user, but does not post the message.

    If I send an email from my website.com address to the gmail account, wp-gmail.php does the same thing as above – posts just the subject, user, and date but with no message.

    In the former two cases, I receive the error:

    Notice: Undefined property: parts in /htdocs/class_mbox.php on line 135

    Warning: Invalid argument supplied for foreach() in /htdocs/class_mbox.php on line 145

    Not sure if this matters or not, but I am using web-based email to send messages as I cannot use outlook due to military reasons.

    Any help would be appreciated!

  12. JC2

    I copied and pasted the code into files: “wp-gmail.php” and “class_mbox.php”.

    I set up the writing options and sent a test email to my gmail account.

    I ran “wp-gmail.php” straight from the browser and got this message…

    ———–
    Fatal error: Call to undefined function: imap_open() in /home/jac2com/public_html/family/class_mbox.php on line 35
    ———–

    I looked at line 35 and this is what I have…

    ———–
    $this->MBOX = imap_open( $this->MBOXSTR, $login, $password );
    ———–

    What should I do?

    - JC2

  13. Tara

    Warning: imap_open(): Couldn’t open stream {pop.gmail.com:995/pop3/ssl/novalidate-cert} in /homepages/1/d89529408/htdocs/tara/wordpress/class_mbox.php on line 35
    Array ( [0] => Can’t open mailbox {pop.gmail.com:995/pop3/ssl/novalidate-cert}: invalid remote specification ) ERROR: Ooops

    Help?

  14. Raenoll's 69 Zone

    让我们一起来Moblogging

    题注:Moblog-移动Blog Moblogger-使用移动工具写Blog的人 Moblogging-使用移动工具写Blog (概念同Blog和Podcast)
      我的第一个Moblog贴应该是数PDX里的了,因为不在家中没有电脑玩,无意中发现了…

  15. Raenoll’s 69 Zone » 让我们一起来Moblogging

    [...] 不支持GMail的安全Pop3协议,想用GMail发布Blog的可以参考matt的这篇文章Wordpress GMail Mobile blogging。当然,想用插件制作Blog的W [...]

  16. Filipe

    Hi,

    I’m having the same error message as Tara, any clue on what might be happening?

    Warning: imap_open(): Couldn’t open stream {pop.gmail.com:995/pop3/ssl} in D:\Program Files\Apache Group\Apache2\htdocs\wordpress\class_mbox.php on line 35
    Array ( [0] => Can’t open mailbox {pop.gmail.com:995/pop3/ssl}: invalid remote specification ) ERROR: Ooops

    thanks in advance,
    Filipe

  17. Filipe

    btw, i removed that “novalidate-cert” parameter just for testing, but the message shows up either with or without it.

  18. Can Random » Blog Archive » M@blog » Blog Archive » Wordpress + Gmail mobile blogging

    [...] blogging Apparently you can get this darn thing working with a Gmail account. M@blog » Blog Archive » Wordpress + Gmail mobile blogging [...]

  19. Fyse

    I’m having the same issues with error messages as Dan. Every time I call the wp-gmail.php script I get…

    Notice: Undefined index: metakeyselect in /home/nrcf2/public_html/fyse-floatingface-com/wp-admin/admin-functions.php on line 378

    Notice: Undefined index: metakeyinput in /home/nrcf2/public_html/fyse-floatingface-com/wp-admin/admin-functions.php on line 379

    Notice: Undefined index: metavalue in /home/nrcf2/public_html/fyse-floatingface-com/wp-admin/admin-functions.php on line 380

    Connection Closed

    I then get a post appearing on my blog with title and date as expected, but no body for the post. Any ideas, anyone?

  20. skippy

    This looks great — GMail is often a problem for wp-mail.php users at the WordPress Support Forums.

    Would you consider contributing your solution to the official Blog by Email instructions?

  21. Blogging Pro China

    [...] 文章,但很可惜的是不支持类似Gmail那样的secure pop3。Matt把用Gmail发布变成了可能。注意:服务器要支持imap_open()。 [...]

  22. S

    I am getting a different connection time-out error : on running wp-gmail.php

    Warning: imap_open(): Couldn’t open stream {pop.gmail.com:995/pop3/ssl/novalidate-cert} in /home/a3lonet/public_html/blog/class_mbox.php on line 35
    Array ( [0] => Can’t connect to gmail-pop.l.google.com,995: Connection timed out [1] => Can’t connect to gmail-pop.l.google.com,995: Connection timed out ) ERROR: Ooops

    btw: where are supposed to place the .php files in the root of wordpress or in /includes or /wp-content/plugins ?

    Regards

  23. Christine

    FFS, thank you so much. I have been struggling with the WP-mail feature for two days to get it working. I am setting up a wordpress blog for my father, and wanted to give him the option of blogging by email so he wouldn’t even have to touch the back-end (the easier, the better, for him!).

    I tried every other option out there, including DE-grading (instead of upgrading) my Wordpress installation a total of five different times. I finally figured out that all the other options were useless with the Google App Domain e-mail address, and this solution works fantastically. I’m currently using Wordpress 2.1.2 (the last “de-grade” I did, and now I’m scared to upgrade it for fear of something else breaking). THANK YOU!

  24. stutimes

    hi!
    i used the wp 2.5.1 when copied the code,there no warning,but it cut post and
    can’t publish also!!!

  25. stutimes

    sorry the word is can’t not cut

  26. mankoff

    If your body is blank that is because an attachment is required. Attach a small something (anything) and then it should work.

  27. 爱情地图

    不错不错M@Blog – by Matthew Romaine » Wordpress + Gmail mobile blogging

  28. Haraye

    I usually dont post in Blogs but your blog forced me to, amazing work.. beautiful

  29. hkdedicatedservers

    If your body is blank that is because an attachment is required. Attach a small something (anything) and then it should work.

Leave a Reply