共用方式為


HOW TO:在連絡人中搜尋電子郵件地址

這個範例會在 [連絡人] 資料夾中搜尋電子郵件地址中含有網域名稱 example.com 的連絡人。

**適用於:**本主題中的資訊適用於 Outlook 2007 和 Outlook 2010 的應用程式層級專案。如需詳細資訊,請參閱依 Office 應用程式和專案類型提供的功能

範例

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    SearchForEmail("example.com")
End Sub

Public Sub SearchForEmail(ByVal partialAddress As String)
    Dim contactMessage As String = String.Empty
    Dim contacts As Outlook.MAPIFolder = Me.Application.ActiveExplorer().Session _
        .GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
    For Each foundContact As Outlook.ContactItem In contacts.Items
        If Not (foundContact.Email1Address Is Nothing) Then
            If foundContact.Email1Address.Contains(partialAddress) Then
                contactMessage = contactMessage & "New contact" _
                & foundContact.FirstName & " " & foundContact.LastName _
                & " Email Address is " & foundContact.Email1Address & _
                ". " & vbCrLf
            End If
        End If
    Next
    If contactMessage.Length > 0 Then
    Else
        contactMessage = "No Contacts were found."
    End If
    MsgBox(contactMessage)
End Sub
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    SearchforEmail("example.com");
}

private void SearchforEmail(string partialAddress)
{
    string contactMessage = string.Empty;
    Outlook.MAPIFolder contacts = (Outlook.MAPIFolder)
        this.Application.ActiveExplorer().Session.GetDefaultFolder
         (Outlook.OlDefaultFolders.olFolderContacts);
    foreach (Outlook.ContactItem foundContact in contacts.Items)
    {
        if (foundContact.Email1Address != null)
        {
            if (foundContact.Email1Address.Contains(partialAddress))
            {
                contactMessage = contactMessage + "New contact"
                + foundContact.FirstName + " " + foundContact.LastName
                + " Email Address is " + foundContact.Email1Address +
                ". \n";
            }
        }
    }
    if (!(contactMessage.Length > 0))
    {
        contactMessage = "No Contacts were found.";
    }
    MessageBox.Show(contactMessage);
}

編譯程式碼

這個範例需要:

  • 電子郵件地址中含有網域名稱 example.com (例如 somebody@example.com) 而且具有名字和姓氏的連絡人。

請參閱

工作

HOW TO:以程式設計方式傳送電子郵件

HOW TO:存取 Outlook 連絡人

HOW TO:將項目加入至 Outlook 連絡人

概念

使用連絡人項目