yet another multiple profiles issue

M

Michael

Hi,

I use Outlook Object Model and Redemption to access calendar type
folders for different outlook profiles.
Next are the main steps that is use:
- Create an Outlook application object.
- Logon to a specific profile.
- Get the required calendar folder by folder ID and store ID.
- Do the work on the appointment items as needed.
- Logoff from the session.
- Perform cleaning (COM objects and so on).

Sometimes I need to do this several times, with different Outlook
profiles, some of them configured with Exchange.
Enerything works fine if the Outlook application is not started.
If the application is already started when I execute my code, I get an
error ("Your profile is not configured.") when I try to get the
calendar folder for an Exchange configured Outlook profile.

I assume this is caused by the session already opened by Outlook.
I tried to logon using the Session class from Redemption and all went
fine, even when Outlook was started. But the problem is that I need to
access all data from an appointment item and I cannot use only
Redemption objects to do this.

So, the main questions are:
- Can I logon to a MAPI session using Redemption, and then using OOM
with that opened session to process appointment items?
- Is there another solution to the problem?

Thank you,
Michael
 
K

Ken Slovak - [MVP - Outlook]

Outlook can only have 1 session open for 1 profile, to change profiles you
must exit Outlook and start it up again.

Why can't you use only Redemption code? The RDO objects let you get at every
property of every type of item, either from an explicit named property or
from the Fields collection.
 
M

Michael

Hi Ken,

First of all I want to thank you for answering.
I didn't want to reply until I do some more research.
Now I have so many questions, but I will try to take it from the bottom
up.
First of all, here's a code snipet:

string folderExch = a correct ID I get from somewhere else;
string storeExch = a correct ID I get from somewhere else;
Redemption.RDOSession session = null;
try
{
session = new Redemption.RDOSession();
session.Logon("exchange profile", Missing.Value, false,
true, Missing.Value, true);
Redemption.RDOFolder calendar =
session.GetFolderFromID(folderExch, storeExch, Missing.Value);
for (int i = 0; i < calendar.Items.Count; i++)
{
Redemption.RDOMail mail = calendar.Items.Item(i);
// this always returns a Redemption.RDOMail object
if (mail.MessageClass == "IPM.Appointment")
//this is always true, since I have a
calendar folder.
}
}
catch (SystemException ex) { MessabeBox.Show(ex.Message); }
finally
{
if ((session != null) && (session.LoggedOn))
session.Logoff();
}

Now, my question would be: can I, in anyway, cast/reinterpret the
RDOMail item to/as an Outlook.AppointmentItem or
Redemption.SafeAppointmentItem?
The main idea behind this would be to logon to a MAPI session using
Redemption, and then using the easy-to-use functionality of the
Outlook.AppointmentItem to work with the fields of the appointment.
I want to avoid statements like the next one:

// inside the for statement from above
Redemption.SafeAppointmentItem appt = new
Redemption.SafeAppointmentItem();
appt.Item = calendar.Items.Item(i);
int PR_BODY = 0x1000001E;
object test = new object();
test = appt.get_Fields(PR_BODY);

This worked, but I got null when I tried to get the start date using:
int PR_START_DATE = 0x00600040;
I want to avoid this because I wouldn't want to dig into Extended MAPI
for the values of all the appointment item properties that I need.
I hope this makes some sense.

Thank you,
Michael
 
M

Michael

Hi Ken,

First of all I want to thank you for answering.
I didn't want to reply until I do some more research.
Now I have more questions in mind. I will try to take it from the
bottom up.
First of all, here is a code snipet:

String folderExch = a correct value I get from somewhere else;
String storeExch = a correct value I get from somewhere else;
Redemption.RDOSession session = null;
try
{
session = new Redemption.RDOSession();
session.Logon("exchange profile", Missing.Value, false, true,
Missing.Value, true);
Redemption.RDOFolder calendar = session.GetFolderFromID(folderExch,
storeExch, Missing.Value);

for (int i = 0; i < calendar.Items.Count; i++)
{
// this always returns a RDOMail item
Redemption.RDOMail mail = calendar.Items.Item(i);
if (mail.MessageClass == "IPM.Appointment")
// this is always true since I have a calendar folder
}
}
catch () {}
finally
{
if ((session != null) && (session.LoggedOn))
session.Logoff();
}

Now, my question: is there a way to cast/reinterpret the RDOMail item
inside the for statement as an Outlook.AppointmentItem?
The main idea behind this is to logon to a MAPI session using
Redemption (this way I don't depend on the Outlook application object)
and then using the easy-to-use interface exposed by the
Outlook.AppointmentItem class to access all of the appointment
information that I need.
I also tried the following:

// inside the above mentioned for statement
Redemption.SafeAppointmentItem appt = new
Redemption.SafeAppointmentItem();
appt.Item = calendar.Items.Item(i);
int PR_BODY = 0x1000001E;
object test = new object();
test = appt.get_Fields(PR_BODY);

This worked, but I failed to get the PR_START_DATE (= 0x00600040)
property for the appointment item. I got a null from the call to
get_Fields.
Anyway, I want to avoid the get_Fields approach, because I wouldn't
want to dig into Extended MAPI for the IDs of all the properties that I
need from an appointment item.
I hope this makes sense.

Thank you,
Michael
 
K

Ken Slovak - [MVP - Outlook]

You cannot directly assign an Outlook appointment item or
SafeAppointmentItem from an RDOMail item. What you can do is get the EntryID
of the RDOMail item and use that to get the item as an Outlook
AppointmentItem using the NameSpace.GetItemFromID method.
 
M

Michael

I see what you mean, but I cannot do it because:

- GetItemFromID is not a static method of the NameSpace class;
- I must create an Outlook.Application object to get the NameSpace
"MAPI" and this automatically uses the Outlook session if the
application is already running.

In my case, I opened Outlook with a profile, and from my application I
connect to another MAPI session using Redemption.
When I get to the point of calling NameSpace.GetItemFromID, I get the
"Your profile is not configured" error, because the Outlook NameSpace
object tried to get the item from the current session of Outlook.

Please let me know if you can think of another aproach to this
situation.

Thank you,
Michael
 
D

Dmitry Streblechenko

In this case all you can do is either use RDOMail.Fields() or wait for the
next version of Redemption to support RDOAppointmentItem object :)

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

Ken Slovak - [MVP - Outlook]

No other approach I can think of, I'd just use the Fields collection of the
RDOMail item myself. I use Fields all the time in my code, it's very easy
once you get used to it and have a tool such as OutlookSpy to see the
necessary property tags and so on.
 
M

Michael

Thank you both for answering.
I will start working on the Fields collection and see what I can do to
ease my work.

When you plan to launch a new version of Redemption? :)
 
D

Dmitry Streblechenko

4.1 with RDONoteItem, RDOPostItem and RDOTaskItem will probably be released
in about 3 months.
4.2 with RDOAppointmentItem is probably another 3 months away, sometime
around August.

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

sabyasachi mukherjee

Hi,

Can you please let me know if I can categorise an Outlook message
programmatically? The category may not be existing in the categories
master.

Thanks in advance.

Regards

Sabyasachi
 
S

Sue Mosher [MVP-Outlook]

Yes, you can, by appending to the value of the MailItem.Categories property.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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