Writing MSMQ Client for MAPI Transport Provider
| Nik Okuntseff |
MS Exchange Server Programming |
Writing MSMQ Client for MAPI Transport Provider
The following code sample (MSMQ/XPPClient) illustrates how one could write
a client to send messages to a MAPI application via the MSMQ MAPI Transport
provider.
#include <windows.h>
#include "mq.h"
int main(void)
{
/*
* Algorithm:
* 1. Open MSMQ MAPI Transport inbound
queue.
* 2. Prepare MQMSGPROPS struct.
* 3. Send a message to the queue.
*/
// I assume this queue name. Replace this as necessary.
#define MY_IN_QUEUE_PATHNAME L"mig\\nokuntseff_mqxp"
// Determine format name of the incoming queue
wchar_t wcsQueueFormatName[MAX_PATH];
DWORD dwSize = MAX_PATH;
HRESULT hRes = ::MQPathNameToFormatName(MY_IN_QUEUE_PATHNAME,
wcsQueueFormatName,
&dwSize);
if (FAILED(hRes))
throw (-1);
// Open it.
QUEUEHANDLE hInQueue = NULL;
hRes = ::MQOpenQueue(wcsQueueFormatName,
MQ_SEND_ACCESS,
MQ_DENY_NONE,
&hInQueue);
if (FAILED(hRes))
throw (-1);
// Prepare MQMSGPROPS struct.
MQMSGPROPS MsgProps;
// We'll send message body only. Arrays of size 1
are enough.
MQPROPVARIANT aVariant[1];
MSGPROPID aPropId[1];
// Define simple message in MSMQ mail format
char * pszMessage = "Mime-Version: 1.0\r\n"
"Date: 9 Apr 1998 17:58:44 +0700\r\n"
"From: Nik Okuntseff<xpp_outbound>\r\n"
"Subject: Hello, world!\r\n"
"X-Delivery-Report-Requested: False\r\n"
"X-Non-Delivery-Report-Requested: True\r\n"
"Content-Transfer-Encoding: binary\r\n"
"To: Nik Okuntseff<nokuntseff_mqxp>\r\n"
"\r\n"
// Empty line separates message body
"Hello, world!\r\n";
// Message body
DWORD dwMessageSize = strlen(pszMessage);
// Set the PROPID_M_BODY property.
aPropId[0] = PROPID_M_BODY;
// PropId
aVariant[0].vt = VT_VECTOR | VT_UI1;
// Type
aVariant[0].caub.cElems = dwMessageSize;
// Size.
aVariant[0].caub.pElems = (unsigned char *) pszMessage;
// Message itself
// Set the MQMSGPROPS structure
MsgProps.cProp = 1; // Number
of properties.
MsgProps.aPropID = aPropId; // Ids of properties.
MsgProps.aPropVar = aVariant; // Values of properties.
MsgProps.aStatus = NULL; // No error report.
hRes = ::MQSendMessage(hInQueue,
&MsgProps,
NULL);
if (FAILED(hRes))
throw (-1);
// Close the queue
hRes = ::MQCloseQueue(hInQueue);
if (FAILED(hRes))
throw (-1);
return 0;
}
This sample is very similar to the XConClient sample. Algorithm is the
same. Message queue is of course different. The message body which is sent
to the queue is also different. The "To:" and "From:" fields are constructed
in format that MAPI transport can understand. Notice that the queue label
alone is used as the recipient address (we had it prefixed with a user
alias when dealing with MSMQ Exchange connector).
You may use this sample to send the "Hello, world!" message to a MAPI
recipient. Reply to this message in a MAPI client and observe outbound
message appear in the outbound queue (xpp_outbound in my case).
[ Contents |
Home
]
Send comments and suggestions to niko@wrconsulting.com
Copyright © 1997-1998 by Nik Okuntseff
|