Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
In diesem Beispiel werden die im Posteingang von Outlook ankommenden ungelesenen Nachrichten von einem bestimmten Absender mit einem Flag versehen.
Betrifft: Die Informationen in diesem Thema betreffen Projekte auf Anwendungsebene für Outlook 2007 und Outlook 2010. Weitere Informationen finden Sie unter Verfügbare Funktionen nach Office-Anwendung und Projekttyp.
Beispiel
Private Sub ThisAddIn_NewMail() Handles Application.NewMail
Dim outlookNameSpace As Outlook.NameSpace = Me.Application.GetNamespace("MAPI")
Dim inbox As Outlook.MAPIFolder = _
outlookNameSpace.GetDefaultFolder( _
Outlook.OlDefaultFolders.olFolderInbox)
' Mark each unread message from Jeff Hay with a yellow flag icon.
Dim unreadMailItems As Outlook.Items = _
inbox.Items.Restrict("[Unread]= true")
For Each omailItem As Object In unreadMailItems
Dim unreadMailItem As Outlook.MailItem = Nothing
unreadMailItem = TryCast(omailItem, Outlook.MailItem)
If (unreadMailItem IsNot Nothing) Then
If (unreadMailItem.SenderName = "Jeff Hay") Then
unreadMailItem.FlagIcon = _
Outlook.OlFlagIcon.olYellowFlagIcon
unreadMailItem.Save()
End If
End If
Next
End Sub
private void ThisAddIn_Startup(object sender,
System.EventArgs e)
{
this.Application.NewMail +=
new Outlook.ApplicationEvents_11_NewMailEventHandler
(ThisAddIn_NewMail);
}
void ThisAddIn_NewMail()
{
Outlook.NameSpace outlookNameSpace = this.Application.GetNamespace("MAPI");
Outlook.MAPIFolder inbox = outlookNameSpace.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderInbox);
// Mark each unread message from Jeff Hay with a yellow flag icon.
Outlook.Items unreadMailItems =
inbox.Items.Restrict("[Unread]= true");
foreach (Object omailItem in unreadMailItems)
{
Outlook.MailItem unreadMailItem =
omailItem as Outlook.MailItem;
if (unreadMailItem != null)
{
if (unreadMailItem.SenderName == "Jeff Hay")
{
unreadMailItem.FlagIcon =
Outlook.OlFlagIcon.olYellowFlagIcon;
unreadMailItem.Save();
}
}
}
}
Siehe auch
Konzepte
Erste Schritte beim Programmieren von Add-Ins auf Anwendungsebene