Microsoft로 로그인
로그인하거나 계정을 만듭니다.
안녕하세요.
다른 계정을 선택합니다.
계정이 여러 개 있음
로그인할 계정을 선택합니다.

요약

이 문서에서는 Microsoft Outlook 10.0 개체 라이브러리를 사용하여 찾기 메서드 및 제한 메서드를 사용하여 특정 메시지를 검색하는 방법을 C#.

추가 정보

Microsoft Outlook 10.0 개체 라이브러리를 사용하여 특정 메시지를 검색하는 경우 다음 단계를 수행합니다.

  1. .NET Microsoft Visual Studio 또는 2005 Microsoft Visual Studio 시작합니다.

  2. 파일 메뉴에서 새로 고를 클릭한 다음, Project.

  3. Visual C# 프로젝트 유형 목록에서 콘솔 애플리케이션을 클릭합니다.

    기본적으로 Class1.cs 파일이 만들어집니다.

    참고 Microsoft Visual C# 2005에서 Visual C# 프로젝트 유형 목록에서 시각적 C#"를 클릭합니다 . 기본적으로 Program.cs가 만들어집니다.

  4. Microsoft Outlook 10.0 개체 라이브러리에 대한 참조를 추가합니다. 이렇게 하여 다음 단계를 수행합니다.

    1. Project 메뉴에서 참조 추가를 클릭합니다.

    2. COM 탭을 클릭하고 Microsoft Outlook 10.0 개체 라이브러리를 찾은 다음 선택을 클릭합니다.

      참고 Microsoft Visual C# 2005. 선택을 클릭할 수 있습니다.

    3. 참조 추가 대화 상자에서 확인을 클릭합니다.

    4. 선택한 라이브러리에 대한 래퍼를 생성하라는 메시지가 표시되면 예를 클릭합니다.

  5. 코드 창에서 코드를 다음으로 바 대체합니다.

    using System;
    using System.Reflection; // to use Missing.Value

    namespace FilterAppointments
    {
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    public static int Main(string[] args)
    {
    try
    {
    // Create an Outlook application.
    Outlook.Application oApp = new Outlook.Application();

    // Get the Mapi NameSpace and the Logon.
    Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi");

    // Log on using dialog to choose a profile.
    oNS.Logon(Missing.Value, Missing.Value, true, true);

    // Alternate Logon using specific profile
    // TODO: Change the profile name where it is appropriate.
    //oNS.Logon("YourValidProfile", Missing.Value, false, true);

    // Get the Calendar folder.
    Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

    // Get the Items collection in the folder.
    Outlook.Items oItems = (Outlook.Items)oCalendar.Items;
    Console.WriteLine("Total Items (unrestricted): " + oItems.Count);

    //Include all occurrences of recurring items, and then sort them.
    oItems.Sort ("[Start]", false);
    oItems.IncludeRecurrences = true;

    // Define the string for the search criteria.
    String sCriteria;

    // Set the criteria for the Date fields.
    sCriteria = "[Start] <= '09/01/2002 08:00 AM' and [End] >= '2/15/2002 08:00 PM'";

    // Set the criteria for a string field.
    // sCriteria = "[Subject] = 'Weekly recurring meeting'";

    // Set the criteria for a numeric field.
    // Look for meetings that have not been responded to.
    // sCriteria = "[ResponseStatus] = " + (Int32)Outlook.OlResponseStatus.olResponseNotResponded)

    // Use the Restrict method to reduce the number of items to process.
    Outlook.Items oRestrictedItems = oItems.Restrict(sCriteria);
    oRestrictedItems.Sort ("[Start]", false);
    oRestrictedItems.IncludeRecurrences = true;

    Console.WriteLine("Total Items Unrestricted : " + oRestrictedItems.Count);

    Outlook.AppointmentItem oAppointment;

    //Get each item until item is null.
    Outlook.AppointmentItem oAppt;
    oAppt = (Outlook.AppointmentItem)oRestrictedItems.GetFirst();
    while (oAppt != null)
    {
    // Console.WriteLine(i.ToString());
    Console.WriteLine(" Subject: " + oAppt.Subject.ToString());
    Console.WriteLine(" Start time: " + oAppt.Start.ToString());
    Console.WriteLine(" End time: " + oAppt.End.ToString());
    Console.WriteLine(" Occurrences: " + oAppt.RecurrenceState.ToString());
    Console.WriteLine("\n\n");
    oAppt = (Outlook.AppointmentItem)oRestrictedItems.GetNext();
    }


    // Use the Find method to get single match.
    sCriteria = "[Start] >= '09/30/2001'";
    Console.WriteLine("Criteria: " + sCriteria.ToString());
    oAppointment = (Outlook.AppointmentItem)oItems.Find(sCriteria);
    Console.WriteLine("Used Find with Date fields");
    if (oAppointment is Outlook.AppointmentItem)
    Console.WriteLine("Found -> " + oAppointment.Subject.ToString());
    else
    Console.WriteLine("No object found");


    // Log off
    oNS.Logoff();

    // Clean up
    oAppointment = null;
    oRestrictedItems = null;
    oItems = null;
    oCalendar = null;
    oNS = null;
    oApp = null;
    }

    //Simple error handling
    catch (Exception e)
    {
    Console.WriteLine("{0} Exception caught.", e);
    }

    //Default return value
    return 0;
    }
    }
    }
  6. 코드에서 TODO 텍스트 문자열을 검색한 다음 환경에 대한 코드를 수정합니다.

  7. F5 키를 눌러 프로그램을 빌드하고 실행합니다.

참조

2002 Outlook 보안 기능에 대한 자세한 내용은 다음 문서 번호를 클릭하여 Microsoft 기술 자료에서 문서를 볼 수 있습니다.

290500 2002


년 Outlook의 개발자 관련 전자 메일 보안 기능에 대한 설명 대규모 컬렉션의 Count 속성을 사용할 때 발생할 수 있는 문제에 대한 추가 정보를 보려면 다음 문서 번호를 클릭하여 Microsoft 기술 자료에서 문서를 볼 수 있습니다.

294385 OL2002: 재발하는 약속을 사용하는 잘못된 Count 속성

도움이 더 필요하세요?

더 많은 옵션을 원하세요?

구독 혜택을 살펴보고, 교육 과정을 찾아보고, 디바이스를 보호하는 방법 등을 알아봅니다.

커뮤니티를 통해 질문하고 답변하고, 피드백을 제공하고, 풍부한 지식을 갖춘 전문가의 의견을 들을 수 있습니다.

이 정보가 유용한가요?

언어 품질에 얼마나 만족하시나요?
사용 경험에 어떠한 영향을 주었나요?
제출을 누르면 피드백이 Microsoft 제품과 서비스를 개선하는 데 사용됩니다. IT 관리자는 이 데이터를 수집할 수 있습니다. 개인정보처리방침

의견 주셔서 감사합니다!

×