SystemtippDieser Artikel bezieht sich auf ein anderes Betriebssystem als das von Ihnen verwendete. Für Sie möglicherweise nicht relevante Artikelinhalte wurden deaktiviert.
Dieser schrittweise aufgebaute Artikel beschreibt eine Out-of-Office-Regel mit Extended MAPI zu erstellen.
Collaboration Data Objects (CDO) 1.21 bietet einen einfachen Mechanismus für Out-of-Office (ABWESEND) Text festlegen und aktivieren den Status ABWESEND, und deaktivieren. Da CDO 1.21 Extended MAPI verwendet, kann die gleichen Ergebnisse mit Extended MAPI-Code erzielt werden. Dies kann nützlich sein, wenn Sie bereits Extended MAPI verwenden und nicht MAPI und CDO mischen möchten.
Erstellen einer OOF-Regel besteht aus zwei Schritten: die Antwortnachricht ABWESEND erstellen und Hinzufügen einer Regel die Regeln für den Posteingang Tabelle.
Der Status ABWESEND deaktivieren, und deaktivieren
Der Status ABWESEND wird in eine boolesche Eigenschaft mit dem Informationsspeicher PR_OOF_STATE gehalten. Festlegen des Status ABWESEND ist so einfach wie das Festlegen dieser Eigenschaft.
/*********************************************************************************
CreateOOF.cpp
This file contains code that demonstrates how to create an OOF rule and enable
OOF using Extended MAPI.
The relevant functions are CreateOOF, which creates the OOF rule, and
SetOOFState, which toggles the OOF state.
To build this code, you need to add the following files to your link settings:
- msvcrt.lib
- edkguid.lib
- edkmapi.lib
- edkdebug.lib
- edkutils.lib
- mapi32.lib
This code is provided as a sample only. Microsoft offers no warranty or
support for it. Use at your own risk.
*********************************************************************************/
#include <mapix.h>
#include <mapidefs.h>
#include <edk.h>
#include <stdio.h>
// Text used in OOF reply.
#define OOF_TEXT "I'm currently out of the office."
// Macro to get the number of bytes needed for MAPIAllocateBuffer for a ROWLIST.
#define CbNewROWLIST(_centries) (offsetof(ROWLIST,aEntries) + (_centries)*sizeof(ROWENTRY))
// Forward function declarations.
HRESULT CreateOOF(LPMAPIFOLDER lpFolder, LPSTR lpszOOFText);
HRESULT SetOOFState(LPMDB lpMDB, bool bState);
// main
void main()
{
HRESULT hRes = S_OK; // MAPI return code.
LPMAPISESSION lpSession = NULL; // Session pointer.
LPMDB lpMDB = NULL; // Information store pointer.
LPMAPIFOLDER lpInbox = NULL; // Folder pointer.
LPENTRYID lpStoreEID = NULL; // Pointer to entry ID of message store.
ULONG cbStoreEID = 0; // Count of bytes in message store entry ID.
LPENTRYID lpInboxEID = NULL; // Pointer to entry ID of Inbox.
ULONG cbInboxEID = 0; // Count of bytes in Inbox entry ID.
ULONG ulObjType = 0; // Object Type indicator.
// Initialize MAPI.
if (FAILED(hRes = MAPIInitialize(NULL)))
{
printf("MAPIInitialize failed in main.\n");
goto error;
}
// Log on.
printf("Choose the profile that you want to create a new OOF rule in.\n");
if (FAILED(hRes = MAPILogonEx(NULL,
NULL,
NULL,
MAPI_LOGON_UI |
MAPI_NEW_SESSION |
MAPI_NO_MAIL,
&lpSession)))
{
printf("MAPILogonEx failed in main.\n");
goto error;
}
// Get the default message store.
if (FAILED(hRes = HrMAPIFindDefaultMsgStore(lpSession,
&cbStoreEID,
&lpStoreEID)))
{
printf("HrMAPIFindDefaultMsgStore failed in main.\n");
goto error;
}
// Open the default message store.
if (FAILED(hRes = lpSession->OpenMsgStore(NULL,
cbStoreEID,
lpStoreEID,
NULL,
MAPI_BEST_ACCESS,
&lpMDB)))
{
printf("OpenMsgStore failed in main.\n");
goto error;
}
// Get the Inbox.
if (FAILED(hRes = lpMDB->GetReceiveFolder(NULL,
NULL,
&cbInboxEID,
&lpInboxEID,
NULL)))
{
printf("GetReceiveFolder failed in main.\n");
goto error;
}
// Open the Inbox.
if (FAILED(hRes = lpMDB->OpenEntry(cbInboxEID,
lpInboxEID,
NULL,
MAPI_BEST_ACCESS,
&ulObjType,
(LPUNKNOWN *)&lpInbox)))
{
printf("OpenEntry failed in main.\n");
goto error;
}
// Create the OOF rule.
if (FAILED(hRes = CreateOOF(lpInbox, OOF_TEXT)))
{
printf("CreateOOF failed in main.\n");
goto error;
}
// Set OOF state to true.
if (FAILED(hRes = SetOOFState(lpMDB, TRUE)))
{
printf("EnableOOF failed in main.\n");
goto error;
}
// Log off.
if (FAILED(hRes = lpSession->Logoff(0,0,0)))
{
printf("Logoff failed in main.\n");
goto error;
}
goto cleanup;
// Report error number.
error:
printf("ERROR: hRes = 0%x\n", hRes);
// Clean up memory and uninitialize MAPI.
cleanup:
if (lpInbox) lpInbox->Release();
if (lpMDB) lpMDB->Release();
if (lpSession) lpSession->Release();
MAPIUninitialize();
}
// CreateOOF.
HRESULT CreateOOF(LPMAPIFOLDER lpFolder, LPSTR lpszOOFText)
{
HRESULT hRes = S_OK; // MAPI return code.
LPMESSAGE lpOOFMsg = NULL; // OOF Message pointer.
LPEXCHANGEMODIFYTABLE lpExchModTable = NULL; // Rule Table pointer.
ACTION *lpAction = NULL; // ACTION pointer.
ACTIONS *lpActions = NULL; // ACTIONS pointer.
SPropValue OOFProps[2]; // Properties to set on OOF message.
SPropValue RuleProps[6]; // Properties to set on OOF rule.
LPSPropValue lpOOFEID = NULL; // PR_ENTRYID for the OOF message.
ULONG ulCount = 0; // Count of props returned by GetProps.
LPROWLIST lpRowList = NULL; // Row List pointer.
SPropTagArray taga = {1, {PR_ENTRYID}}; // Props to return from GetProps.
// Open the rules table with an IExchangeModifyTable interface.
if (FAILED(hRes = lpFolder->OpenProperty(PR_RULES_TABLE,
(LPGUID)&IID_IExchangeModifyTable,
0,
MAPI_DEFERRED_ERRORS,
(LPUNKNOWN *)&lpExchModTable)))
{
printf("OpenProperty failed in CreateOOF.\n");
goto error;
}
// Create a new message in the associated contents table.
if (FAILED(hRes = lpFolder->CreateMessage(NULL,
MAPI_DEFERRED_ERRORS |
MAPI_ASSOCIATED,
&lpOOFMsg)))
{
printf("CreateMessage failed in CreateOOF.\n");
goto error;
}
// Set up the property structure for the OOF message properties.
// First the body.
OOFProps[0].ulPropTag = PR_BODY;
OOFProps[0].Value.lpszA = lpszOOFText;
// Then the message class.
OOFProps[1].ulPropTag = PR_MESSAGE_CLASS;
OOFProps[1].Value.lpszA = "IPM.Note.Rules.OofTemplate.Microsoft";
// Set the properties on the message.
if (FAILED(hRes = lpOOFMsg->SetProps(2, OOFProps, NULL)))
{
printf("SetProps failed in CreateOOF.\n");
goto error;
}
// Commit our changes to the message.
if (FAILED(hRes = lpOOFMsg->SaveChanges(KEEP_OPEN_READWRITE | FORCE_SAVE)))
{
printf("SaveChanges failed in CreateOOF.\n");
goto error;
}
// Get the entry ID of the message.
if (FAILED(hRes = lpOOFMsg->GetProps(&taga, NULL, &ulCount, &lpOOFEID)))
{
printf("GetProps failed in CreateOOF.\n");
goto error;
}
// Allocate space for an ACTION structure.
if (FAILED(hRes = MAPIAllocateBuffer(sizeof(ACTION), (LPVOID *) &lpAction)))
{
printf("MAPIAllocateBuffer for ACTION failed in CreateOOF.\n");
goto error;
}
// Allocate space for an ACTIONS structure.
if (FAILED(hRes = MAPIAllocateBuffer(sizeof(ACTIONS), (LPVOID *) &lpActions)))
{
printf("MAPIAllocateBuffer for ACTIONS failed in CreateOOF.\n");
goto error;
}
// Clear the memory.
memset(lpAction, 0, sizeof(ACTION));
memset(lpActions, 0, sizeof(ACTIONS));
// Set up the ACTIONS structure.
// Set the rule version
lpActions->ulVersion = EDK_RULES_VERSION;
// Set the number of actions
lpActions->cActions = 1;
// Set the pointer to the action
lpActions->lpAction = lpAction;
// Set up the ACTION structure.
// Set up the type of action.
lpAction->acttype = OP_OOF_REPLY;
// Because it is an OOF reply, associate the action with our OOF message.
lpAction->actReply.cbEntryId = lpOOFEID->Value.bin.cb;
lpAction->actReply.lpEntryId = (LPENTRYID)lpOOFEID->Value.bin.lpb;
// Clear the ReplyTemplate GUID.
memset(&lpAction->actReply.guidReplyTemplate, 0, sizeof(GUID));
// Set up the rule properties.
// Set rule sequence to 0.
RuleProps[0].ulPropTag = PR_RULE_SEQUENCE;
RuleProps[0].Value.ul = 0;
// Set the rule provider.
RuleProps[1].ulPropTag = PR_RULE_PROVIDER;
RuleProps[1].Value.lpszA = "MSFT:TDX OOF Rules";
// Set the rule state for OOF.
RuleProps[2].ulPropTag = PR_RULE_STATE;
RuleProps[2].Value.ul = ST_ENABLED | ST_KEEP_OOF_HIST | ST_ONLY_WHEN_OOF;
// Set the user flags to 2.
RuleProps[3].ulPropTag = PR_RULE_USER_FLAGS;
RuleProps[3].Value.ul = 2;
// Set the condition to NULL (fires on all messages).
RuleProps[4].ulPropTag = PR_RULE_CONDITION;
RuleProps[4].Value.ul = NULL;
// Set the actions for the rule to our ACTIONS structure.
RuleProps[5].ulPropTag = PR_RULE_ACTIONS;
RuleProps[5].Value.ul = (ULONG) lpActions;
// Allocate space for the rowlist for ModifyTable.
if (FAILED(hRes = MAPIAllocateBuffer(CbNewROWLIST(1), (LPVOID *)&lpRowList)))
{
printf("MAPIAllocateBuffer for ROWLIST failed in CreateOOF.\n");
goto error;
}
// Set up the row list.
// Number of entries.
lpRowList->cEntries = 1;
// Type of operation.
lpRowList->aEntries->ulRowFlags = ROW_ADD;
// Number of properties being set.
lpRowList->aEntries->cValues = 6;
// Pointer to properties.
lpRowList->aEntries->rgPropVals = RuleProps;
// Call ModifyTable on rule table to add our OOF rule.
if (FAILED(hRes = lpExchModTable->ModifyTable(0, lpRowList)))
{
printf("ModifyTable failed in CreateOOF.\n");
goto error;
}
goto cleanup;
// Report error.
error:
printf("ERROR: hRes = 0%x\n", hRes);
// Clean up memory.
cleanup:
if (lpRowList) MAPIFreeBuffer(lpRowList);
if (lpAction) MAPIFreeBuffer(lpAction);
if (lpActions) MAPIFreeBuffer(lpActions);
if (lpOOFMsg) lpOOFMsg->Release();
return hRes;
}
// SetOOFState
HRESULT SetOOFState(LPMDB lpMDB, bool bState)
{
HRESULT hRes = S_OK; // MAPI Return code
SPropValue OOFProp; // OOF property
// Set up the OOF property.
OOFProp.ulPropTag = PR_OOF_STATE;
OOFProp.Value.b = bState;
// Set the property on the information store.
if (FAILED(hRes = lpMDB->SetProps(1, &OOFProp, NULL)))
goto error;
return hRes;
// Report error.
error:
printf("Error in EnableOOF. OOF State couldn't be set.\n");
printf("hRes = 0%x\n", hRes);
return hRes;
}
Wichtig: Dieser Artikel wurde maschinell und nicht von einem Menschen übersetzt. Die Microsoft Knowledge Base ist sehr umfangreich und ihre Inhalte werden ständig ergänzt beziehungsweise überarbeitet. Um Ihnen dennoch alle Inhalte auf Deutsch anbieten zu können, werden viele Artikel nicht von Menschen, sondern von Übersetzungsprogrammen übersetzt, die kontinuierlich optimiert werden. Doch noch sind maschinell übersetzte Texte in der Regel nicht perfekt, insbesondere hinsichtlich Grammatik und des Einsatzes von Fremdwörtern sowie Fachbegriffen. Microsoft übernimmt keine Gewähr für die sprachliche Qualität oder die technische Richtigkeit der Übersetzungen und ist nicht für Probleme haftbar, die direkt oder indirekt durch Übersetzungsfehler oder die Verwendung der übersetzten Inhalte durch Kunden entstehen könnten.
Den englischen Originalartikel können Sie über folgenden Link abrufen: 308281
(http://support.microsoft.com/kb/308281/en-us/
)
Microsoft stellt Ihnen die in der Knowledge Base angebotenen Artikel und Informationen als Service-Leistung zur Verfügung. Microsoft übernimmt keinerlei Gewährleistung dafür, dass die angebotenen Artikel und Informationen auch in Ihrer Einsatzumgebung die erwünschten Ergebnisse erzielen. Die Entscheidung darüber, ob und in welcher Form Sie die angebotenen Artikel und Informationen nutzen, liegt daher allein bei Ihnen. Mit Ausnahme der gesetzlichen Haftung für Vorsatz ist jede Haftung von Microsoft im Zusammenhang mit Ihrer Nutzung dieser Artikel oder Informationen ausgeschlossen.
Bitte geben Sie Ihr Feedback zu diesem Artikel ab
Hat dieser Artikel bei der Lösung Ihres Problems geholfen?
Ja
Nein
Ich weiß nicht
Waren die Informationen für Ihr Problem relevant?
Ja
Nein
Wie hoch war der Aufwand für Sie persönlich, um diesen Artikel zu verwenden?
Sehr gering
Gering
Mäßig
Hoch
Sehr hoch
Wie könnte man den Artikelinhalt verbessern?
Hinweis: Leider können wir keine Kommentare persönlich beantworten.
Danke! Dieses Feedback hilft uns dabei, die Supportartikel weiter zu verbessern. Weitere Informationen finden Sie auf der Hilfe und Support-Startseite.