Exchange 2007 Mail Contact going to Gmail and Calendar Integration

A mail contact in Exchange 2007 that points to a Gmail account and the complaint was that they did not get proper calendar invites, they got a text email with the dreaded winmail.dat

The fix is to edit the mail contact in Exchange and change the Rich Text Format to Never for the contact.

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.

  • 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';

// 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";

$cal = new Zend_Gdata_Calendar($client);

$calFeed = $cal->getCalendarListFeed();

foreach ($calFeed as $calendar)
    if ($calendar->title->text == $ourCal)
  //$ourCalUrl = explode('/',$calendar->id);
  //$ourCalUrl = ''. $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');

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
//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);
$msg .= "got Email || ";

$mail = mailparse_msg_create();
$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']))
 $msg .= "regex matched || ";



Gmail SSL Proxy

Everybody loves Gmail, but if you are trying to integrate other system i.e a ticket system that does not support ssl it might be a pain.

You can use as a proxy to connect your application to gmail.

  • Download and install delegate
  • run the command below(it will setup delegate to be a pop ssl proxy on port 110.)
delegated -P110 SERVER=POP FSV=sslway admin=<your email>

In your application the pop server is localhost and your username is myuser%[email protected]:995(since the proxy is generic, the username has the additional connection information so you can poll multiple accounts witht he same proxy) and the password is your usual gmail password