Unique Identifer for Mailitem

P

Paulem0071

I need to get a unique identifier for a mailitem, and access to EntryID is
throwing a "Type Library not Registered" error. Here is my code:

Outlook.Folder folder =
(Outlook.Folder)this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

string filter = @"@SQL=(""urn:schemas:httpmail:fromemail"" = '" +
_mailItem.SenderEmailAddress + "' ";

Outlook.Items items = folder.Items.Restrict(filter);
items.Sort("[CreationTime]", true);
foreach (Outlook.MailItem mailItem in items)
{

if (mailItem != null)
{
if (mailItem.CreationTime != null)
{
string f = mailItem.EntryID; //cannot access
cDate = mailItem.CreationTime.ToString("MM-dd
HH:mm");



}
//call delegate
taskPane.ListAddItem(cDate);

}

}

Thank you. I need a unique identifer I can like back to to access the
original message item. Do not want to use sender and date/time . Thank you.
 
P

Paulem0071

Here is more info, I'm gettting this error (Library not Registered) when
running trying to access MailItem.Display and MailItem.Attachments[x] too.

Thanks a lot
 
K

Ken Slovak - [MVP - Outlook]

Is the Outlook PIA installed? Are you running on the same version of Outlook
as the code is developed on? What version of Outlook? What version of the
Framework? Where is the code running (standalone, addin, what)?




Paulem0071 said:
Here is more info, I'm gettting this error (Library not Registered) when
running trying to access MailItem.Display and MailItem.Attachments[x] too.

Thanks a lot

Paulem0071 said:
I need to get a unique identifier for a mailitem, and access to EntryID
is
throwing a "Type Library not Registered" error. Here is my code:

Outlook.Folder folder =
(Outlook.Folder)this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

string filter = @"@SQL=(""urn:schemas:httpmail:fromemail"" = '" +
_mailItem.SenderEmailAddress + "' ";

Outlook.Items items = folder.Items.Restrict(filter);
items.Sort("[CreationTime]", true);
foreach (Outlook.MailItem mailItem in items)
{

if (mailItem != null)
{
if (mailItem.CreationTime != null)
{
string f = mailItem.EntryID; //cannot access
cDate = mailItem.CreationTime.ToString("MM-dd
HH:mm");



}
//call delegate
taskPane.ListAddItem(cDate);

}

}

Thank you. I need a unique identifer I can like back to to access the
original message item. Do not want to use sender and date/time . Thank
you.
 
P

Paulem0071

Ken,

Thank you for your reply.

Yes, the Outlook PIA is installed, and just about everything else works
fine. I am using Framwork v3.5 and the code is in a task pane Add-In.

Another error I get when accessing Entry ID on a mailItem is xF3840108: The
item's properties and methods canot be used inside this event procedure at
Microsoft.Office.Interop.Outlook._MailItem.get_EntryID()

Thank you

Ken Slovak - said:
Is the Outlook PIA installed? Are you running on the same version of Outlook
as the code is developed on? What version of Outlook? What version of the
Framework? Where is the code running (standalone, addin, what)?




Paulem0071 said:
Here is more info, I'm gettting this error (Library not Registered) when
running trying to access MailItem.Display and MailItem.Attachments[x] too.

Thanks a lot

Paulem0071 said:
I need to get a unique identifier for a mailitem, and access to EntryID
is
throwing a "Type Library not Registered" error. Here is my code:

Outlook.Folder folder =
(Outlook.Folder)this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

string filter = @"@SQL=(""urn:schemas:httpmail:fromemail"" = '" +
_mailItem.SenderEmailAddress + "' ";

Outlook.Items items = folder.Items.Restrict(filter);
items.Sort("[CreationTime]", true);
foreach (Outlook.MailItem mailItem in items)
{

if (mailItem != null)
{
if (mailItem.CreationTime != null)
{
string f = mailItem.EntryID; //cannot access
cDate = mailItem.CreationTime.ToString("MM-dd
HH:mm");



}
//call delegate
taskPane.ListAddItem(cDate);

}

}

Thank you. I need a unique identifer I can like back to to access the
original message item. Do not want to use sender and date/time . Thank
you.
 
K

Ken Slovak - [MVP - Outlook]

I've never heard of or seen that sort of problem unless the wrong version of
Outlook is referenced or possibly the PIA's are damaged. If you have access
to another dev machine you can test your code there and see what happens,
otherwise I'd start by repairing Office and uninstalling and reinstalling
the PIA's. Beyond that I'm at a loss.

Something is definitely screwy though since getting an EntryID is not an
even procedure.
 
P

Paulem0071

Ken,

Thank you. I receive the error on another machine as well. Other
properties, such as CreateTime work, however. EntryID, Attachments and some
others do not. I am probably accessing the mail folder and iterating through
the items incorrectly. Do you have a simple code example of an Outlook
Add-In that sucessfully reads a MailItem.EntryID from OL2007?

Thank you
 
K

Ken Slovak - [MVP - Outlook]

There's no mystery about it.

If you have a valid MailItem then EntryID is a valid property and you can
read it. If the item hasn't been saved previously then EntryID will be null
or null string or Empty, depending on what language and development platform
you're using, but that's about it. In .NET code I just use something like
this, assuming oMail is the MailItem:

string id = oMail.EntryID;

If you then plan to use the value you can test for
!String.IsNullOrEmpty(id).

Other than running in debug mode and looking at the values for your mail
item object to see what's showing, about the only other thing I can think of
would be to try using a for loop rather than a foreach loop and see what
happens.

I'd also use a test before casting as a mail item to see if the item was
actually a mail item since Inbox can hold other item types. But that would
cause a System.InvalidCastException error and not what you're seeing.

I ran the same code here without the restriction on the items collection and
used a Debug.WriteLine(f) statement and every EntryID was written out with
no errors for any of the mail items in the Inbox.
 
P

Paulem0071

Ken,

Thanks to your message, I was able to figure out what is going on, but do
not have a solution:

After removing the filter, I noticed that for messages of IPM.Note,
everything works fine, but for those of IPM.Note.Company.Voicemail,
everything falls apart. This is a custom MessageClass and form.

My objective is to display all voicemails from a particular email party.

I tried referencing the custom form exe, but it didn't work.

Any ideas?
 
K

Ken Slovak - [MVP - Outlook]

I don't follow. Are you saying that items with that message class are firing
errors when you try to read the EntryID?

That just doesn't make sense. Even with the custom message class they still
are mail items and every single Outlook item of every type has an EntryID
property.

I suppose you could try using reflection on the items that fire an error and
using that to try to get at EntryID, but it still doesn't make any sense to
me. Can you run in debug mode and stop on one of those items and use the
locals window to look at the properties exposed by those items and see
what's there, especially EntryID?
 

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

Similar Threads


Top