Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Add-Ins / November 2003

Tip: Looking for answers? Try searching our database.

Strange behavior in Outlook object model

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pete Davis - 26 Nov 2003 19:28 GMT
I've got several things that are throwing me off and I could use some help.

I've written a plugin in C#. The plugin aspect works fine.

When I receive a new e-mail, I would like to find each new e-mail. I'm not
sure what the best way to do it is, but what I've resorted to (and I don't
like it) is to try to iterate through all the folders and find every e-mail
since the last time I checked. I then perform some stuff on each e-mail.

There are several issues here:

GetFirst and GetNext: I can't use the foreach() construct in C# because
there is no enumerator. The next thing I tried was something like this:

Outlook.MailItem mi = null;
for (int index = 0; index < folders.Items.Count; index++)
{
   mi = (Outlook.MailItem) folders.Items.Item(index);
}

This, however, throws an exception, even though the items are MailItems.

I then tried this:

Outlook.MailItem mi = (Outlook.MailItem) folder.Items.GetFirst()
while (null != mi)
{
   ...
   mi = (Outlook.MailItem) folder.Items.GetNext()
}

Except in this case, GetNext() always seems to return the first item. What's
up with that? Isn't it supposed to go to the next item?

My second problem has to do with getting the time from the messages.

If I do:

DateTime dt = mi.SentOn;
or
DateTime dt = mi.ReceivedTime;

I always get 6/20/2002 7:32:10PM

I'm real close to accomplishing what I want to do, if I can just get this
crap ironed out. Thanks.

Pete
Dmitry Streblechenko - 26 Nov 2003 23:17 GMT
1. Are you sure they all are mailitems? How about NDRs, etc?
The reason why GetNext does not work for you is because every time you call
it, your code retrieves a new instance of the Items object. Store the Items
object in a local variable to make sure you are always using the same
instance:

Outlook.Items Items= folder.Items;
Outlook.MailItem mi = Items.GetFirst()
while (null != mi)
{
    ...
    mi = (Outlook.MailItem)Items.GetNext()
}

2. See #1, you were probably always getting the same item.

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

> I've got several things that are throwing me off and I could use some help.
>
[quoted text clipped - 44 lines]
>
> Pete
Pete Davis - 26 Nov 2003 23:30 GMT
Thanks, that was it. I guess it makes sense that it needs to keep its
placeholder in the local copy.

Pete

> 1. Are you sure they all are mailitems? How about NDRs, etc?
> The reason why GetNext does not work for you is because every time you call
[quoted text clipped - 68 lines]
> >
> > Pete
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.