Setting recipient name when creating a message via IMAPIFolder::CreateMessage

0.00 avg. rating (0% score) - 0 votes

The following code will create a message in MAPI Sent Items folder. Pocket Outlook will show the recipient name (instead of the recipient number) when the message is displayed.

//create an empty message first
LPMESSAGE pmsg
;
hr
= currentFolder->CreateMessage(NULL, 0, &pmsg);

//create a single recipient
SPropValue propRecipient
[4];
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 = _T(“SMS”);

//This will show when the message is open in Outlook. Without this, only the number is displayed
propRecipient
[2].ulPropTag = PR_DISPLAY_NAME;
propRecipient
[2].Value.lpszW = L“Message Recipient Name”;
propRecipient
[3].ulPropTag = PR_EMAIL_ADDRESS;
propRecipient
[3].Value.lpszW = msgRecipient;

//array of recipients
ADRLIST adrlist
;
adrlist
.cEntries = 1; //1 recipient
adrlist
.aEntries[0].cValues = 4; //each recipient has 4 properties
adrlist
.aEntries[0].rgPropVals = (LPSPropValue)(&propRecipient);

//attach recipient list to message
hr
= pmsg->ModifyRecipients(MODRECIP_ADD, &adrlist);

//change other properties
SPropValue props
[4];
ZeroMemory(&props, sizeof(props));
props
[0].ulPropTag = PR_SUBJECT; //PR_SUBJECT points to SMS contents
props
[0].Value.lpszW = msgSubject;
props
[1].ulPropTag = PR_MESSAGE_CLASS;//type of message. Without this it’ll be an email
props
[1].Value.lpszW = TEXT(“IPM.SMStext”);
props
[2].ulPropTag = PR_MESSAGE_FLAGS; //mark message as read
props
[2].Value.ul = MSGFLAG_READ | MSGFLAG_FROMME | MSGFLAG_UNSENT;

//set delivery time to system time
SYSTEMTIME stNow
;
FILETIME ftNow
;
GetSystemTime(&stNow);
SystemTimeToFileTime(&stNow, &ftNow)
props
[3].ulPropTag = PR_MESSAGE_DELIVERY_TIME;
props
[3].Value.ft = ftNow;

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


To find a recipient name given the number, use FindMatchingContact or IPOutlookItemCollection.Find API.


Reference: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3852632&SiteID=1

0.00 avg. rating (0% score) - 0 votes
ToughDev

ToughDev

A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>