0

I'm trying to convert a Microsoft.Graph.Contact object into a PST file for Outlook using Extended MAPI, and I don't know where to feed the contact's email addresses to and have it show when I open the contact in Outlook, and wanted to know how I can do that with Microsoft's MAPI SDK.

EDIT: I managed to create the new property

const GUID PSETID_Address = {0x00062004, 0, 0, {0xC0, 0, 0, 0, 0, 0, 0, 0x46}};


LPSPropTagArray cols = NULL;

MAPINAMEID  sa = {
  (LPGUID) &PSETID_Address,
  MNID_ID,
  0x8083
};

LPMAPINAMEID sample = {
  &sa
};

hr = obj->GetIDsFromNames(1, &sample, MAPI_CREATE, &cols);

SPropValue values[1];
//I'm setting other contact fields. This code is just for brevity. (There's more than 1 property)
values[0].ulPropTag = PROP_TAG(PT_UNICODE, cols->aulPropTag[0]);
values[0].Value.lpszW = L"[email protected]";
LPSPropProblemArray problems = NULL;
hr = obj->SetProps(1, values, &problems);

SetProps then fails with "The parameter is not correct." What am I doing wrong here?

1 Answer 1

6

Email1 is in {00062004-0000-0000-C000-000000000046} / 0x8083 / PT_UNICODE.
You can see that (and all other) properties in OutlookSpy (I am its author):

enter image description here

Sign up to request clarification or add additional context in comments.

11 Comments

Thanks, but do you know how to create this object in c++?
Sure, first you open/create the PST store, open the IPM root folder, create your contacts folder (IMAPIFolder.CreateFolder), then IMessage (IMAPIFolder.CreateMessage), etc. If you've never done Extended MAPI, the learning curve is pretty steep. Have you looked into Redemption (I am also its author)? It similar to the Outlook Object Model, but allows you to work with PST files without adding them to an Outlook profile (RDOSession.LogonPstStore) and can be used without any user interaction as long as the MAPI system (and hence desktop Outlook) is installed.
thanks for the heads up on SAPI. Certainly the errors returned do not help in the slightest.
ulKind needs to be MNID_ID, the id must be 0x8083.
Also keep in mind that for Outlook to see and use the email, you need to set a few more properties (entry id, display name, etc.) - take a look at IMessage in OuitlookSpy.
I've set the ulKind to MNID_ID with the value of 0x8083. Am I coming at this wrong? It still gives me "The Parameter is not correct" HR code -2147024809. Even gone so far as to try to look at what's coming back for property problems but it remains NULL.
Ended up solving it by calling CHANGE_PROP_TYPE() instead of PROP_TAG which I didn't know existed until now. Thank you for your help.
Ah, yes, one assumes 2 byte prop and shift the value up by 16 bits, the other only changes the lower 16 bits to set the type.
{00062004-0000-0000-C000-000000000046} is also known as PSETID_Address, see Commonly used property sets
Thank you so much for that. That helped get me on the right track. One more question and that's on the edit.
Your code doesn't compile as you can't assign a string literal to a LONG. You need to use Kind.lpwstrName instead of Kind.lID. Also, you are not checking GetIDsOfNames() for failure, and you are ignoring the output info provided by the lppProblems parameter of SetProps()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.