Access MaiItem.UserProperties using Redemption

M

MA

Hi,

I am using the Redemption to create a message. I need to add the user
defined fields to the message.

I know the Outlook.MaiItem has the UserProperties which allow to add
field and optionally attach to the folder. However, UserProperties not
available in Redemption.

How can I access the UserProperties from the RDOMail?

--------------------------------------------
// Get the RDOFolder
session.MAPIOBJECT = olApp.Session.MAPIOBJECT;
RDOFolder rdoFolder = session.GetFolderFromPath(@"\\Bob Builder
\Inbox");

// Create the message
RDOMail msg = rdoFolder.Items.Add("IPM.Note.CRM");
msg.Sent = true;
msg.Subject = String.Format("Test sent message: {0}", DateTime.Now);
RDORecipient recipient = msg.Recipients.Add("(e-mail address removed)");
recipient.Resolve(false, null);
msg.Sender = session.CurrentUser;
msg.SentOn = Convert.ToDateTime("2007/09/10",
System.Globalization.CultureInfo.CurrentCulture);
msg.Body = "Test message body";
msg.Save();
---------------------------------------------

Thanks for looking at the issue.

Regards,
MA
 
M

MA

Thanks Dmitry for your answer.

The RDOMail does not seems to have the "Fields" property. I can see
the set_Fields, get_Fields, GetPropList, etc. Am I missing something
in here?

Thanks in advance for your suggestions.

Regards,
MA
 
M

MA

Basically, I want to add the add the fields to the message. I can do
this using the Outlook MailItem. I am not sure how to use it when
using the Redemption.RDOMail item. Should I need to access the Outlook
MailItem after I create the message using the RDOMail (see the source
code above).

Could you please provide some example.

Example below which uses the Outlook.MailItem:
<quote>
Outlook.MailItem msg = folder.Items.Add("IPM.Note") as MailItem;
msg.UserProperties.Add("Test Field",
Outlook.OlUserPropertyType.olText, true, "")
</quote>


Thanks,
MA
 
M

MA

Thanks for your suggestions.

I have tried the following code which did not add the custom field.
-------------------------------------------------------
rdoMsg.set_Fields("http://schemas.microsoft.com/mapi/string/
{00063034-0000-0000-C000-000000000046}/UDF1", "test value");
rdoMsg.Save();
-------------------------------------------------------

However, I can add the custom field using the code below:

-------------------------------------------------------
rdoMsg.HTMLBody = "test <STRONG>message</STRONG> body.";
rdoMsg.Save();

Outlook.MailItem olMsg =
(Outlook.MailItem)olNameSpace.GetItemFromID(rdoMsg.EntryID, "");
Outlook.UserProperty udf = olMsg.UserProperties.Add("UDF1",
Outlook.OlUserPropertyType.olText, false, false);
olMsg.UserProperties["UDF1"].Value = "Some value";
olMsg.Save();
-------------------------------------------------------

Am I missing something?

Thanks,
MA
 
D

Dmitry Streblechenko

Where and when are you using the added user property? Can you see it in
OutlookSpy when you click IMessage?
The values of the user properties are stored as regular named MAPI
properties (that is what rdoMsg.set_Fields will do for you).
Outlook however (when you use MailItem.UserProperties.Add) also adds the
property *definition* to a special blob (you can also see it in OutlookSpy).
If the property defintiion is not added (Redemption does not do that),
MailItem.UserProperties collection won't see it even if the value is there.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
M

MA

Thanks for the clarification.

It make sense now and I can see the property when I use the IMessage
(Love the OutlookSpy).

I need to locate the fields using the Outlook client. In this case,
the fields need to be added to the folder definitions. The following
code works fine.
-----------------------------------------------------
Outlook.MailItem olMsg =
(Outlook.MailItem)olNameSpace.GetItemFromID(rdoMsg.EntryID, "");
Outlook.UserProperty udf = olMsg.UserProperties.Add("UDF4",
Outlook.OlUserPropertyType.olText, true,
Outlook.OlUserPropertyType.olText);
olMsg.UserProperties["UDF4"].Value = "Test value";
olMsg.Save();
-----------------------------------------------------

Any suggestions.

Thanks,
MA
 
M

MA

Thanks.

I have tried the following code without any success. The
RDOFolderField - "field" object return null. I have tried without GUID
by passing null value. String.empty on Guid return exception. Any
suggestions?

------------------------------------
RDOFolder2 rdoFolder2 = (RDOFolder2)rdoFolder;
RDOFolderField field = rdoFolder2.FolderFields.Add("UDF2",
Redemption.rdoUserPropertyType.olText, "{00020329-0000-0000-
C000-000000000046}", 0);

if (field != null)
rdoFolder2.FolderFields.Save();
 
D

Dmitry Streblechenko

What is the *exact* error message?
Firstly, if you want the default value of a parameter, pass Missing.Value
rather null or empty string.
Secondly, every time you use multiple dot notation (e.g.
rdoFolder2.FolderFields.Add), you get back a brand new COM object back every
time, so when you call rdoFolder2.FolderFields.Save, you won't get any new
fields. Cache the value of the FolderFields object:

RDOFolder2 rdoFolder2 = (RDOFolder2)rdoFolder;
RDOFolderFields fields = rdoFolder2.FolderFields;
RDOFolderField field =fields.Add("UDF2", rdoUserPropertyType.olText,
Missing.Value, Missing.Value);
fields.Save;

Also try the following VB script (you can run it from "Script Editor" in
OutlookSpy):

set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Folder =
Session.GetFolderFromID(Application.ActiveExplorer.CurrentFolder.EntryID)
set FolderFields = Folder.FolderFields
set Field = FolderFields.Add("Redemption Text Prop")
'set Field = FolderFields.Add("Redemption Percent Prop", &HD, ,2)
'olPercent, 2 decimals
set Field = FolderFields.Add("Redemption Number Prop", &HC, ,3) 'olNumber, 2
decimals
FolderFields.Save

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top