Share via


방법: 연락처에서 전자 메일 주소 검색

이 예제에서는 전자 메일 주소에 도메인 이름 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) 성과 이름이 있는 연락처

참고 항목

작업

방법: 프로그래밍 방식으로 전자 메일 보내기

방법: Outlook 연락처 액세스

방법: Outlook 연락처에 엔트리 추가

개념

연락처 항목 작업