// Import the ADO and CDOEX DLLs.
#import "C:\Program Files\Common Files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF"), named_guids
#import "C:\Program Files\Common Files\Microsoft Shared\CDO\cdoex.dll" no_namespace
STDMETHODIMP CATLSink::OnSyncSave(IExStoreEventInfo * pEventInfo, BSTR bstrURLItem, LONG lFlags)
{
HRESULT hr = S_OK;
// Only do this at the beginning of the transaction.
if (lFlags & EVT_SYNC_BEGIN)
{
// Cast pEventInfo to a IExStoreDispEventInfoPtr.
IExStoreDispEventInfoPtr pDispInfo = pEventInfo;
// Create a new message.
IMessagePtr iMsg(__uuidof(Message));
_RecordPtr rec;
char szSubject[256];
char szTextBody[256];
// Get the record that caused the event.
// This is the new message.
pDispInfo->get_EventRecord((IDispatch**)&rec);
// Set up a reply.
iMsg->From = "notifier@microsoft.com";
// Set the recipient to the sender of the message that caused the event.
iMsg->To = rec->Fields->GetItem("urn:schemas:httpmail:fromemail")->Value.bstrVal;
// Set up the subject string to contain the subject of the message that caused the event.
sprintf(szSubject,"Message Received: %s", (char*)(_bstr_t)rec->Fields->GetItem("urn:schemas:httpmail:subject")->Value.bstrVal);
iMsg->Subject = szSubject;
// Set up the text of the message to contain the URL to the message that caused the event.
sprintf(szTextBody, "The following item was received:\n%s", (char*)(_bstr_t)bstrURLItem);
iMsg->TextBody = szTextBody;
// Send the message.
iMsg->Send();
iMsg = NULL;
}
return hr;
}