Code Repo    |     RSS
MD's Technical Sharing



Friday, November 21, 2008

Sending MMS via MAPI

The following code snippet can place an MMS into MMS Outbox folder and cause the

phone to attempt to send the MMS, but a failure (error message: Unable to send MMS. Your message will remain in Outbox folder.) is reported just after the MMS data connection is established. The native composer can send and receive MMS successfully.


// pointer to folder having PR_CE_IPM_DRAFTS_ENTRYID in message store with
PR_DISPLAY_NAME
= "MMS", e.g. drafts folder of MMS account


// This has been retrieved (code not shown)
IMAPIFolder
* pfldrDrafts = NULL;

//pointer to message being created
LPMESSAGE pmsg
;

//create the message to be sent
hr
= pfldrDrafts->CreateMessage(NULL, 0, &pmsg);

//add recipients
SPropValue propRecipient
[3];
ZeroMemory(&propRecipient, sizeof(propRecipient));
propRecipient
[0].ulPropTag = PR_RECIPIENT_TYPE;
propRecipient
[0].Value.l = MAPI_TO;
propRecipient
[1].ulPropTag = PR_ADDRTYPE;
propRecipient
[1].Value.lpszW = L"MMS"; //originally this is L"SMS", I changed
to MMS to point to MMS account
propRecipient
[2].ulPropTag = PR_EMAIL_ADDRESS;
propRecipient
[2].Value.lpszW = L"111111"; //recipient phone number
ADRLIST adrlist
;
adrlist
.cEntries = 1;
adrlist
.aEntries[0].cValues = 3;
adrlist
.aEntries[0].rgPropVals = (LPSPropValue)(&propRecipient);
hr
= pmsg->ModifyRecipients(MODRECIP_ADD, &adrlist);

//change other properties
SPropValue props
[4];
ZeroMemory(&props, sizeof(props));

//PR_SUBJECT points to MMS contents. For simplicity, the MMS body and attachments

(pictures, audio has not yet been set)
props
[0].ulPropTag = PR_SUBJECT;
props
[0].Value.lpszW = L"Hello World"; //message subject

//mark message as being sent out
props
[1].ulPropTag = PR_MSG_STATUS;
props
[1].Value.ul = MSGSTATUS_RECTYPE_SMS; //is it OK to use this flag (designed

for SMS)? or is there a similiar flag for MMS?
props
[2].ulPropTag = PR_MESSAGE_FLAGS;
props
[2].Value.ul = MSGFLAG_FROMME | MSGFLAG_UNSENT;

//assign the property to the message
hr
= pmsg->SetProps(sizeof(props) / sizeof(props[0]), (LPSPropValue)&props,
NULL
);

//send the message
hr
= pmsg->SubmitMessage(0);


The above code can send SMS successfully just by modifying pfldrDrafts to point to SMS message store and change propRecipient[1].Value.lpszW as commented. How to make the code send an MMS successfully?

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.