Article ID: 178319
Article Last Modified on 8/18/2005
HRESULT SendMapiMessage()
{
HRESULT hr;
LPMESSAGE lpMsg = NULL;
MAPINAMEID NamedID;
LPMAPINAMEID lpNmid = &NamedID;
LPMAPIFORMINFO lpFormInfo = NULL;
LPMAPIFORMMGR lpMgr = NULL;
SPropValue pProp;
LPSPropTagArray lpNamedPropTags = NULL;
SMAPIFormPropArray *lpFrmPropAry =NULL;
// Create a new message
hr=lpFolder->CreateMessage(NULL,MAPI_DEFERRED_ERRORS,&lpMsg);
if(FAILED(hr)) goto oops;
// Open Forms Manager
hr=MAPIOpenFormMgr(poSession,&lpMgr);
if(FAILED(hr)) goto oops;
// Get the Forms Info object
hr=lpMgr->ResolveMessageClass("IPM.NOTE.MyNote",
MAPIFORM_EXACTMATCH,lpFolder,&lpFormInfo);
if(FAILED(hr)) goto oops;
// Get all the published properties of the form
hr = lpFormInfo->CalcFormPropSet(0,&lpFrmPropAry );
if (FAILED(hr)) goto oops;
// Set First Property for demonstration purposes
// You could set all the properties here if you wished
// by using each element in the aFormProp array
NamedID = lpFrmPropAry ->aFormProp[0].nmid;
// Get Tags for these properties
hr = lpMsg->GetIDsFromNames(1, &lpNmid, MAPI_CREATE,
&lpNamedPropTags);
if(hr) goto oops;
// Create a typed property tag
pProp.ulPropTag = PROP_TAG(PT_STRING8,
PROP_ID(lpNamedPropTags->aulPropTag[0]));
pProp.dwAlignPad = 0L;
pProp.Value.lpszA = "Your string here";
// Set the property
hr = HrSetOneProp(lpMsg, &pProp);
// Set EFD property to allow EFD to read and set fields.
// You should check your VB code to ensure that this is
// the correct name of the field in your project
NamedID.lpguid = (LPGUID) &PS_PUBLIC_STRINGS;
NamedID.ulKind = MNID_STRING;
NamedID.Kind.lpwstrName = L"MS_EXCHANGE_01";
// Once again, get the ID
hr = lpMsg->GetIDsFromNames(1, &lpNmid , MAPI_CREATE,
&lpNamedPropTags);
if(hr) goto oops;
// Once again create a typed property tag
pProp.ulPropTag = PROP_TAG(PT_BOOLEAN,
PROP_ID(lpNamedPropTags->aulPropTag[0]));
pProp.dwAlignPad = 0L;
pProp.Value.b = 1;
// And once again set the property
// Normally you would want to use one call to SetProps
// with an array of properties to set
hr = HrSetOneProp(lpMsg, &pProp);
// Set Message Class - this could be set with other props
// Setting here for illustration purposes
pProp.ulPropTag = PR_MESSAGE_CLASS;
pProp.dwAlignPad = 0L;
pProp.Value.lpszA = "IPM.NOTE.MyNote";
hr = HrSetOneProp(lpMsg, &pProp);
if (hr) goto oops;
// Here you would set all other outgoing Message props
hr = SetOutgoingProps(lpMsg);
if (hr) goto oops;
// Here you would set the recipients of your message
hr = SetRecips(lpMsg);
if (hr) goto oops;
// Finally, sumbit the message
hr = lpMsg->SubmitMessage(0);
if (hr) goto oops;
oops:
// Normally you would free up your memory and
// Release your objects
return S_OK;
}
Additional query words: Form forms EFD designer exchange display named property
Keywords: kbhowto kbmsg kbcode KB178319