Gewusst wie: Flags für eingehende E-Mail-Elemente festlegen
Aktualisiert: November 2007
Betrifft |
---|
Die Informationen in diesem Thema gelten nur für die angegebenen Visual Studio Tools for Office-Projekte und Versionen von Microsoft Office. Projekttyp
Microsoft Office-Version
Weitere Informationen hierzu finden Sie unter Verfügbare Features nach Anwendung und Projekttyp. |
In diesem Beispiel werden die im Posteingang von Outlook ankommenden ungelesenen Nachrichten von einem bestimmten Absender mit einem Flag versehen.
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