[C++] [MAPI] Open a message store !

Hi,

I'm trying to send mail via MAPi on a smartphone, with the SDK Sample "SendMail" i can send put mail in the activesync message store but the mail had to be send on smartphone synchronisation with a PC running Outlook !
I use this code :


while (SUCCEEDED(pTable->QueryRows(1, 0, &psrs)) && (posted < 1))
{
// Check number of rows returned. Since the above call only asks for one,
// anything else means we are at the end of the table
if (1 != psrs->cRows)
{
break;
}

for(unsigned int i=0; i<psrs->aRow[0].cValues; ++i)
{
LPSPropValue lpProp = &psrs->aRow[0].lpPropsIdea;
if(lpProp->ulPropTag == PR_DISPLAY_NAME)
{

_LOG(TEXT(""),0);
_LOG(TEXT("CMailSender::SendPictureByMail Account name => %s"),lpProp->Value.LPSZ);
}
}

// Open this message store, the bug must comes from here !


hr = pSession->OpenMsgStore(NULL,
psrs->aRow[0].lpProps[0].Value.bin.cb,
(ENTRYID *)psrs->aRow[0].lpProps[0].Value.bin.lpb,
NULL,
0,
&pStore);

EXIT_ON_FAILED(hr);

// Now get the Drafts folder. In order for a message to be sent by MAPI, it must be created
// in the Drafts folder
hr = pStore->GetProps((SPropTagArray *)rgTags, MAPI_UNICODE, &cValues, &rgprops);
EXIT_ON_FAILED(hr);

hr = pStore->OpenEntry(rgprops[0].Value.bin.cb,
(LPENTRYID)rgprops[0].Value.bin.lpb,
NULL,
MAPI_MODIFY,
NULL,
reinterpret_cast <IUnknown **>(&pfldrDrafts));

EXIT_ON_FAILED(hr);


// Now create a message...
hr = pfldrDrafts->CreateMessage(NULL, 0, &pmsg);
EXIT_ON_FAILED(hr);
_LOG(TEXT("Message properties setted"),0);

// Now set the some properties on the message....
CMailSender::SetMessageProps(pmsg,picName,to,msg);
_LOG(TEXT("Message properties setted"),0);

// attach a file
hr = CMailSender::AttachFile(pmsg,picName);
EXIT_ON_FAILED(hr);
_LOG(TEXT("File attached"),0);

// Now send the message
hr = pmsg->SubmitMessage(0);
EXIT_ON_FAILED(hr);
posted++;


// Clean up
MAPIFreeBuffer(rgprops);
MAPIFreeBuffer(rgpropsMsg);
FreeProws(psrs);

rgprops = NULL;
rgpropsMsg = NULL;
psrs = NULL;

RELEASE_OBJ(pmsg);
RELEASE_OBJ(pfldrDrafts);
RELEASE_OBJ(pStore);
}


The probleme is that i really don't know how to put my mail in an other account, i can read account names but i can't use them, i guess the answer is near this line


// Open this message store, the bug must comes from here !
hr = pSession->OpenMsgStore(NULL,
psrs->aRow[0].lpProps[0].Value.bin.cb,
(ENTRYID *)psrs->aRow[0].lpProps[0].Value.bin.lpb,
NULL,
0,
&pStore);

But i really don't know how opn a specific message store.
Some one can help me ?

[3572 byte] By [lmussier] at [2008-2-23]
# 1

Ok it's done, simplye change

hr = pSession->OpenMsgStore(NULL,
psrs->aRow[0].lpProps[0].Value.bin.cb,
(ENTRYID *)psrs->aRow[0].lpProps[0].Value.bin.lpb,
NULL,
0,
&pStore);

with


hr = pSession->OpenMsgStore(NULL,
psrs->aRow[0].lpProps[1].Value.bin.cb,
(ENTRYID *)psrs->aRow[0].lpProps[1].Value.bin.lpb,
NULL,
0,
&pStore);

If some one can explain me why :s
So i can put my mail on a specific outlook account, but i still have to presse the "send" key. How to send the mail immediatly after puted it in the account folder ?

lmussier at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices Native C++ Development...
# 2

In Window Mobile 5.0, there's a new API: MailSyncMessages() which does exactly this.

Before Windows Mobile 5.0, it's a bit more complicated. You need to invoke the messaging app twice:
tmail.exe -service "ActiveSync"
tmail.exe -sync

JasonFuller at 2007-9-9 > top of Msdn Tech,Smart Device Development,Smart Devices Native C++ Development...