This is a Email to Google Calendar Quickadd gateway.

You can email a special address and it will take the subject of the email and send it to googles quickadd feature. This is a simple way to add events to your google calendar via email.
http://www.google.com/calendar
http://framework.zend.com/download/gdata
http://www.google.com/support/calendar/bin/answer.py?hl=en&answer=36604

  • You need to have Zend’s Gdata framework installed.
  • The first code example you need to add your google calendar information
  • the 2nd peice of code parses the email and calls the the quickadd function
  • In cpanel setup a forwarder and pipe it to a program of TOGcal.php
<?php //GoogleCal-Functions.php

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');

// Enter your Google account credentials
$email = '[email protected]';
$passwd = 'MyPass';
$ourCal = 'Cal Name';
$ourCalUrl = '';
try {
 $client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, 'cl');
 }
catch(Zend_Gdata_App_AuthException $ex)
{
    echo "Unable to authenticate";
    exit(1);
 }

$cal = new Zend_Gdata_Calendar($client);

$calFeed = $cal->getCalendarListFeed();

foreach ($calFeed as $calendar)
{
    if ($calendar->title->text == $ourCal)
 {
  //$ourCalUrl = explode('/',$calendar->id);
  //$ourCalUrl = 'http://www.google.com/calendar/feeds/'. $ourCalUrl[6] . '/private/full';
  $ourCalUrl = $calendar->getSelfLink()->getHref() . '/private/full';
  $ourCalUrl = str_replace("default/", "",$ourCalUrl);
 }
 //echo $calendar->title->text . " || " . $calendar->getSelfLink()->getHref() . "
";
}
 //echo $ourCalUrl;
 //echo $client->getUri(true);
 //createQuickAddEvent ($client ,$ourCalUrl,'WO Test at Jun 2, 2008 8:00am - Jun 6, 2008 5:00pm');
 //createEvent($client,$ourCalUrl);

function createQuickAddEvent ($client, $URI = NULL, $quickAddText) {
  $gdataCal = new Zend_Gdata_Calendar($client);
  $event = $gdataCal->newEventEntry();
  $event->content = $gdataCal->newContent($quickAddText);
  $event->quickAdd = $gdataCal->newQuickAdd(true);

  $newEvent = $gdataCal->insertEvent($event,$URI);
  return $newEvent->id->text;
}

/**
 * Creates an event on the authenticated user's default calendar with the
 * specified event details.
 *
 * @param  Zend_Http_Client $client    The authenticated client object
 * @param  string           $title     The event title
 * @param  string           $desc      The detailed description of the event
 * @param  string           $where
 * @param  string           $startDate The start date of the event in YYYY-MM-DD format
 * @param  string           $startTime The start time of the event in HH:MM 24hr format
 * @param  string           $endDate   The end date of the event in YYYY-MM-DD format
 * @param  string           $endTime   The end time of the event in HH:MM 24hr format
 * @param  string           $tzOffset  The offset from GMT/UTC in [+-]DD format (eg -08)
 * @return string The ID URL for the event.
 */
function createEvent ($client, $URI = NULL, $title = 'Tennis with Beth', $desc='Meet for a quick lesson', $where = 'On the courts',$startDate = '2008-06-20', $startTime = '9:00',$endDate = '2008-06-20', $endTime = '14:00', $tzOffset = '-04')
{
  $gc = new Zend_Gdata_Calendar($client);
  $newEntry = $gc->newEventEntry();
  $newEntry->title = $gc->newTitle(trim($title));
  $newEntry->where  = array($gc->newWhere($where));

  $newEntry->content = $gc->newContent($desc);
  $newEntry->content->type = 'text';

  $when = $gc->newWhen();
  $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
  $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
  $newEntry->when = array($when);

  echo $URI."||".$title."||".$desc."||".$where."||".$startDate."||".$startTime."||".$endDate."||".$endTime."||".$tzOffset;
  $createdEntry = $gc->insertEvent($newEntry, $URI);
  return $createdEntry->id->text;
}
?>
#!/usr/bin/php -q
<?php
//TOGcal.php
//Takes the subject and uses quickadd to create an event.
include "GoogleCal-Functions.php";

$msg = "";
$email ='';
$fd = fopen("php://stdin", "r");
while (!feof($fd))
{
 $email .= fread($fd, 1024);
}
fclose($fd);
$msg .= "got Email || ";

$mail = mailparse_msg_create();
mailparse_msg_parse($mail,$email);
$struct = mailparse_msg_get_structure($mail);
$section = mailparse_msg_get_part($mail, "1");
$info = mailparse_msg_get_part_data($section);

$msg .= $info['headers']['from'] . " || " . $info['headers']['subject']  . " || ";

//valid sending domains
if (preg_match('/@mydomain\.com/', $info['headers']['from']))
{
 createQuickAddEvent($client,$ourCalUrl,$info['headers']['subject']);
 $msg .= "regex matched || ";
} 
mailparse_msg_free($mail);

//emailError($msg);


?>

10 thoughts on “This is a Email to Google Calendar Quickadd gateway.”

  1. In trying to get this to work, I am having trouble. I get a local delivery failed.

    Two questions.

    1. Do I have to include the Zend framework info in php.ini?

    2. Which URL do I use in GCal-Functions?

    Thanks..

    Chris

  2. If you get a second I could really use the help…there should be another comment in moderation. Sorry to bug you.

    Chris

  3. For those who are interested in this functionality, but not willing to set up a PHP script (or don’t have a place to host it, etc), I recently created a (free) service that does exactly what’s described here:

    http://www.myeventbot.com/

    I’d welcome any & all feedback!

  4. Fatal error: Call to undefined function mailparse_msg_create() in M:\www\rick\wordpress\email-test.php on line 16

    I have zend gdata in a folder called Zend in the same dir as my two pages.
    when i run it. i get the error above.
    this is the line it is stopping on: $mail = mailparse_msg_create();

    ideas?

  5. Mailparse for me is working properly in browser but it’s giving call to undefined function in command line

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.