次の方法で共有


方法 : 受信メール アイテムにフラグを設定する

この例では、ユーザーの Outlook の [受信トレイ] に特定の差出人から電子メール メッセージが届いたときに、その未読メッセージにフラグを設定します。

対象: このトピックの情報は、Outlook 2007 と Outlook 2010 のアプリケーション レベルのプロジェクトに適用されます。詳細については、「Office アプリケーションおよびプロジェクト タイプ別の使用可能な機能」を参照してください。

使用例

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();
            }
        }
    }
}

参照

概念

メール アイテムの操作

アプリケーション レベルのアドインのプログラミングについて