Outlook: Mark a mailitem as complete

P

pnp

Hi

I have a problem marking a mailitem as complete, and having the 'V' icon
appear in the Outlook UI. Im coding a VSTO Addin (C#).

What i am doing is in short this:

1. When outlook receives a mail a test it for subject, and if "valid" i move
it to another folder.
2. In this folder i mark the mail with a red flag.
3. I then examine the mail, does some sql and so forth..
4. When done, i want to flag the mail complete if all went well.

1,2,3 is fixed (nr 2 after reading :
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=68162&SiteID=1). Below
is some of my sourcecode (all the relevant).

My problem is that the mail keeps the red flag icon even though it is marked
as complete. How do I get this 'completedIcon' to appear instead?

Best regards
Anders

------------ CODE EXAMPLE START ------------

//move the mail
Outlook.MailItem movedMail =
(Outlook.MailItem)newMail.Move(myOutlookFolder);
//Get the movemail again, necessary to avoid the movedMail being marked as
not sent
movedMail =
(Outlook.MailItem)GetNamespace("MAPI").GetItemFromID(movedMail.EntryID,
myOutlookFolder.StoreID);

// mark as read, red flag, and save
movedMail.UnRead = false;
movedMail.FlagStatus =
Microsoft.Office.Interop.Outlook.OlFlagStatus.olFlagMarked;
movedMail.FlagIcon =
Microsoft.Office.Interop.Outlook.OlFlagIcon.olRedFlagIcon;
movedMail.Save();

//Do my actions on the mail, sql, xml and so forth.
// ......

//When all goes good - set flagstatus as complete and save.
movedMail.FlagStatus =
Microsoft.Office.Interop.Outlook.OlFlagStatus.olFlagComplete;
movedMail.Save();

------------ CODE EXAMPLE END ------------
 
P

pnp

I've done that. But that just makes the flag disappear. (as the name kind of
says)

And appearently you can't mark a mail item complete without a flag.

At least thats my experience...

/Anders
 
K

Ken Slovak - [MVP - Outlook]

Well, I use VB 6 and Redemption code (www.dimastr.com/redemption) mostly so
I can access various properties that aren't exposed in the Outlook object
model to do what you're trying to do, so my code isn't directly translatable
into .NET code without the use of Redemption, but here's what I do:

Const FLAG_COMPLETED = 1

Const PR_FLAG_COMPLETE_TIME = &H10910040

With oMail
.ReminderSet = False

.FlagIcon = Empty

.FlagStatus = FLAG_COMPLETED

'times stored in GMT, convert local time to GMT
.Fields(PR_FLAG_COMPLETE_TIME) = rdmUtils.HrLocalToGMT(Now)

.Save
End With

The FlagCompleteTime property isn't exposed in the OOM, so that's what
Redemption would be needed for. I'm not sure if it would work without
setting that property, but the rest of the code should be translatable to
..NET code directly.
 
P

pnp

I have almost the same code..

What would "empty" translate to in .NET? I set the flagIcon = olNoFlagIcon.
That might be the difference.

Otherwise i do the same, except for the FlagCompleteTime.

/Anders
 
P

pnp

If I understand VB6 correct, empty is what in VB.NET is Nothing, equal to
'null' in C#.

But - I can't set the FlagIcon to null in C# because it's a value property
and not an object.

Any other ideas?

/Anders
 
P

pnp

Now it seems to work. I have added some more properties, and it seems to work
fine now.

Heres the C# code i use to mark the mailitem complete.

---------- CODE BEGIN ------------
private void markMailItemComplete(Outlook.MailItem email)
{
email.FlagIcon =
Microsoft.Office.Interop.Outlook.OlFlagIcon.olNoFlagIcon;
email.FlagStatus =
Microsoft.Office.Interop.Outlook.OlFlagStatus.olFlagComplete;
email.FlagRequest = "Completed";
email.ReminderSet = false;
email.Save();
}
----------- CODE END -------------

This seems to do the trick. I don't know if it was because I was missing the
FlagRequest and ReminderSet before or just because the order was another, I
think i sat the FlagComplete status before FlagIcon = olNoFlagIcon?

Anyway, it seems to work as supposed now.

So have a nice weekend, and thanks for your help.

/Anders
 
K

Ken Slovak - [MVP - Outlook]

Good, I'm glad you got it working.

I believe what you could supply instead of Empty for C# would be a
System.MissingValue. I'll have to try that when I get a chance.
 

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