问题
I need an advice. We're developing an Outlook add-in with .net, and i need to investigate, if there's a way to create some custom marking for emails. We need to perform an operation on the email, depending on whether it was performed on that email before or not, and display this condition on the Outlook UI (like "read", "unread"). Could you advice something?
回答1:
You can do this with Categories in Outlook 2007 or later. Categories are a color coding label system that work well for this because you can put one or more categories on an email, and the addin can create new categories as needed. Sadly I don't have useful example code in C#, but I do have some in VB.net that should still be helpful. :)
For your specific problem you'd process the emails, then use a category to mark that you'd already processed those emails. Because category labels also show up in the UI, the user will be able to see it easily.
Private Shared ReadOnly CATEGORY_TEST As String = "Custom Overdue Activity"
' This method checks if our custom category exists, and creates it if it doesn't.
Private Sub SetupCategories()
Dim categoryList As Categories = Application.Session.Categories
For i As Integer = 1 To categoryList.Count
Dim c As Category = categoryList(i)
If c.Name.Equals(CATEGORY_TEST) Then
Return
End If
Next
categoryList.Add(CATEGORY_TEST, Outlook.OlCategoryColor.olCategoryColorDarkOlive)
End Sub
' This snippet creates a new Task in Outlook, and assigns the category.
' The process for categories is similar when putting them on an email instead.
' Some of the data here is coming from a web service call in a larger app, you can ignore that. :)
Dim task As Outlook.TaskItem = DirectCast(Application.CreateItem(Outlook.OlItemType.olTaskItem), Outlook.TaskItem)
task.DueDate = Date.Parse(activity.ActDate)
task.StartDate = task.DueDate
task.Subject = String.Format(subjectText, activity.AppID)
task.Body = String.Format(bodyText, activity.AppID, activity.FileNum, activity.AppID)
task.ReminderTime = Now.AddMinutes(10)
task.ReminderSet = True
task.Categories = CATEGORY_TEST
task.Save()
task.Close(OlInspectorClose.olDiscard)
来源:https://stackoverflow.com/questions/4886004/outlook-add-in-email-item-marks