http://www.microsoft.com/korea/msdn/library/odc_ol2003_ta/html/odc_OLOMwVBNET.asp
----------------------------------------------------------------------------------------------------------------------
Microsoft Office Outlook 2003과 Visual Basic .NET을 사용한 편리한 작업
Frank Rice
Microsoft Corporation
적용 대상:
Microsoft Office Outlook 2003
Microsoft Visual Basic .NET
요약: Outlook에는 기본 제공 기능을 사용할 수 있는 여러 가지 개체와 메서드가 있습니다. 이 문서에서는 프로그래밍 방식으로 약속을 만들고, 받은 편지함에서 읽지 않은 메시지를 검색하고, 연락처를 검색하는 데 사용되는 개체와 메서드를 비롯한 다양한 개체와 메서드에 대해 설명합니다. (인쇄 매수 11매)
목차
서론
약속 만들기
모임 요청 만들기
받은 편지함에서 읽지 않은 메시지 검색
연락처 검색
결론
서론
사용자 지정 Microsoft Office Outlook 개체를 만들고 이 개체를 Microsoft Office Outlook 2003이나 다른 응용 프로그램 내에서 조정할 수 있습니다. Microsoft Visual Basic, Microsoft VBA(Visual Basic for Applications) 및 Microsoft Visual Basic .NET 코드를 사용하여 Outlook 개체를 조정할 수 있습니다. Outlook 개체 모델에서는 Outlook 기능에 프로그래밍 방식으로 액세스하는 데 사용하는 Outlook 개체를 제공합니다. 이 문서에서는 Visual Basic .NET을 사용하여 Outlook의 몇 가지 일반 작업을 수행하는 방법에 대해 설명합니다.
약속 만들기
이 단원에서는 Visual Basic .NET의 Outlook 2003 개체 모델을 사용하여 약속을 만드는 방법에 대해 설명합니다. 일정의 기본 항목인 약속에는 일정과 시간만 필요하며 다른 참석자나 리소스는 필요하지 않습니다. 아래에서 알 수 있듯이 일정에서 약속은 시작 시간과 종료 시간에 해당하는 시간 슬롯으로 표시됩니다.
아래의 코드나 약속 또는 모임에 관련된 임의 코드에서 중요한 개체는
AppointmentItem 개체입니다.
AppointmentItem 개체는 일정 폴더에서 약속을 나타냅니다.
AppointmentItem 개체는 약속, 모임(참석자와 리소스가 있는 약속) 또는 반복되는 약속과 모임을 나타낼 수 있습니다.
- Microsoft Visual Studio .NET을 시작합니다.
- 파일 메뉴에서 새로 만들기를 클릭하고 프로젝트를 클릭합니다.
- 프로젝트 형식에서 Visual Basic 프로젝트를 선택하고 서식 파일에서 콘솔 응용 프로그램을 클릭합니다. 기본적으로 Module1.vb가 만들어집니다.
- "Microsoft Outlook 11.0 개체 라이브러리"에 참조를 추가합니다. 참조를 추가하려면 다음 단계를 수행합니다.
- 프로젝트 메뉴에서 참조 추가를 클릭합니다.
- COM 탭에서 Microsoft Outlook 11.0 개체 라이브러리를 클릭한 다음 선택을 클릭합니다.
- 참조 추가 대화 상자에서 확인을 클릭하여 선택을 수락합니다. 선택한 라이브러리에 대해 래퍼를 만들 것인지 묻는 메시지가 나타나면 예를 클릭합니다.
- 코드 창에서 기존의 모든 코드를 다음 코드로 바꿉니다.
Imports System.Reflection
Imports Outlook = Microsoft.Office.Interop.Outlook
Module Module1
Sub Main()
' Create an Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
' Create a new AppointmentItem.
Dim oAppt As Outlook.AppointmentItem = oApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
' Set some common properties.
oAppt.Subject = "Created using OOM in VB .NET"
oAppt.Body = "Hello World"
oAppt.Location = "Room 1201"
oAppt.Start = Convert.ToDateTime("05/31/2004 9:00:00 AM")
oAppt.End = Convert.ToDateTime("05/31/2004 1:00:00 PM")
oAppt.ReminderSet = True
oAppt.ReminderMinutesBeforeStart = 5
oAppt.BusyStatus = Outlook.OlBusyStatus.olBusy
oAppt.IsOnlineMeeting = False
' Save to Calendar.
oAppt.Save()
' Clean up.
oApp = Nothing
oAppt = Nothing
End Sub
End Module
- 사용자 상황에 맞게 코드를 변경합니다.
- F5를 눌러 프로그램을 빌드하고 실행합니다.
- 약속이 만들어졌는지 확인합니다.
모임 요청 만들기
이 단원에서는 Visual Basic .NET의 Outlook 개체 모델을 사용하여 모임 요청을 만드는 방법에 대해 설명합니다.
AppointmentItem 개체가 일회성 약속을 나타낼 수 있는 것처럼 일회성 또는 반복되는 모임도 나타낼 수 있습니다. 일반적으로 모임에는 2명 이상의 사람이 포함됩니다.
AppointmentItem 개체를 다른 참석자에게 보내면 모임이 만들어집니다. 이 개체는 참석자의 받은 편지함 폴더에
MeetingItem 개체의 형태로 수신됩니다.
MeetingItem 개체는 직접 보낼 수 없습니다. 그 대신 상태가
olMeeting으로 설정된
AppointmentItem 개체를 사용자가 보내면 Outlook에서 MeetingStatus 개체를 만듭니다. 다음은 코드 사용의 예입니다.
- Visual Studio .NET을 시작합니다.
- 파일 메뉴에서 새로 만들기를 클릭하고 프로젝트를 클릭합니다.
- 프로젝트 형식에서 Visual Basic 프로젝트를 선택하고 서식 파일에서 콘솔 응용 프로그램을 클릭합니다. 기본적으로 Module1.vb가 만들어집니다.
- "Microsoft Outlook 11.0 개체 라이브러리"에 참조를 추가합니다. 참조를 추가하려면 다음 단계를 수행합니다.
- 프로젝트 메뉴에서 참조 추가를 클릭합니다.
- COM 탭에서 Microsoft Outlook 11.0 개체 라이브러리를 클릭한 다음 선택을 클릭합니다.
- 참조 추가 대화 상자에서 확인을 클릭하여 선택을 수락합니다. 선택한 라이브러리에 대해 래퍼를 만들 것인지 묻는 메시지가 나타나면 예를 클릭합니다.
- 코드 창에서 모든 코드를 다음 코드로 바꿉니다.
Imports System.Reflection
Imports Outlook = Microsoft.Office.Interop.Outlook
Module Module1
Sub Main()
' Create an Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
' Create an AppointmentItem.
Dim oAppt As Outlook._AppointmentItem = oApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
' Change AppointmentItem to a Meeting.
oAppt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting
' Set some common properties.
oAppt.Subject = "Created using OOM in VB.NET"
oAppt.Body = "Hello World"
oAppt.Location = "Room 1201"
oAppt.Start = Convert.ToDateTime("05/31/2004 9:00:00 AM")
oAppt.End = Convert.ToDateTime("05/31/2004 1:00:00 PM")
oAppt.ReminderSet = True
oAppt.ReminderMinutesBeforeStart = 5
oAppt.BusyStatus = Outlook.OlBusyStatus.olBusy
oAppt.IsOnlineMeeting = False
oAppt.AllDayEvent = False
'Add attendees. This statement will display the Addressbook
'Security dialog box. For more information, see the
'security information in the article "What's 'New in
'Microsoft Office Outlook 2003 for Developers"? The URL is
'available at the end of this article.
Dim oRecipts As Outlook.Recipients = oAppt.Recipients
' Add required attendee.
Dim oRecipt As Outlook.Recipient
oRecipt = oRecipts.Add("UserTest1")
oRecipt.Type = Outlook.OlMeetingRecipientType.olRequired
' Add optional attendee.
oRecipt = oRecipts.Add("UserTest2")
oRecipt.Type = Outlook.OlMeetingRecipientType.olOptional
oRecipts.ResolveAll()
'Send out a request. The warning "A program is trying
'to automatically send e-mail on your behalf." will appear.
'with this command. For more information, see the article
'"What's 'New in Microsoft Office Outlook 2003 for
'Developers?" The URL appears at the end of this article.
oAppt.Send()
' Clean up.
oApp = Nothing
oAppt = Nothing
oRecipts = Nothing
oRecipt = Nothing
End Sub
End Module
- 사용자 상황에 맞게 코드를 변경합니다.
- F5를 눌러 프로그램을 빌드하고 실행합니다.
- 모임 요청이 만들어졌는지 확인합니다.
받은 편지함에서 읽지 않은 메시지 검색
이 단원에서는 Microsoft Outlook 11.0 개체 라이브러리를 사용하여 Visual Basic .NET의 Outlook 받은 편지함에서 읽지 않은 메시지를 검색하는 방법에 대해 설명합니다. 다음 절차에서 사용되는 메서드 중 하나는
GetDefaultFolder 메서드입니다.
Namespace 개체의
GetDefaultFolder 메서드는 사서함 폴더라고도 하는 루트 폴더의 폴더에 액세스합니다. 사서함 폴더에는 기본 제공 폴더와 사용자 지정 폴더가 모두 포함됩니다. 사서함 폴더에 참조를 추가하는 한 가지 방법은 열거 중 하나를
GetDefaultFolder 메서드로 지정하는 것입니다. 이 절차의 경우는 받은 편지함을 나타내는
olFolderInbox입니다.
- Visual Studio .NET을 시작합니다.
- 파일 메뉴에서 새로 만들기를 클릭하고 프로젝트를 클릭합니다.
- 프로젝트 형식에서 Visual Basic 프로젝트를 선택하고 서식 파일에서 콘솔 응용 프로그램을 클릭합니다. 기본적으로 Module1.vb가 만들어집니다.
- "Microsoft Outlook 11.0 개체 라이브러리"에 참조를 추가합니다. 참조를 추가하려면 다음 단계를 수행합니다.
- 프로젝트 메뉴에서 참조 추가를 클릭합니다.
- COM 탭에서 Microsoft Outlook 11.0 개체 라이브러리를 클릭한 다음 선택을 클릭합니다.
- 참조 추가 대화 상자에서 확인을 클릭합니다. 선택한 라이브러리에 대해 래퍼를 만들 것인지 묻는 메시지가 나타나면 예를 클릭합니다.
- 코드 창에서 기본 코드를 다음 코드로 바꿉니다.
Imports System.Reflection
Imports Outlook = Microsoft.Office.Interop.Outlook
Module Module1
Sub Main()
' Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application
' String used for comparison with mail item.
Dim sClassComp = "IPM.Note"
' Get Mapi NameSpace.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
' Get Messages collection of Inbox.
Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim oItems As Outlook.Items = oInbox.Items
Console.WriteLine("Total : " & oItems.Count)
' Get unread e-mail messages.
oItems = oItems.Restrict("[Unread] = true")
Console.WriteLine("Total Unread : " & oItems.Count)
' Loop each unread message.
Dim oMsg As Outlook.MailItem
Dim i As Integer
For i = 1 To oItems.Count
'Test to make sure item is a mail item
'and not a meeting request.
If oItems.Item(i).MessageClass = sClassComp Then
oMsg = oItems.Item(i)
Console.WriteLine(i)
Console.WriteLine(oMsg.SenderName)
Console.WriteLine(oMsg.Subject)
Console.WriteLine(oMsg.ReceivedTime)
Console.WriteLine(oMsg.Body)
Console.WriteLine("---------------------------")
End If
Next
' Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oMsg = Nothing
End Sub
End Module
- 사용자 상황에 맞게 코드를 변경합니다.
- F5를 눌러 응용 프로그램을 빌드하고 실행합니다.
- 읽지 않은 메시지가 검색되었는지 확인합니다.
연락처 검색
이 단원에서는 Microsoft Outlook 11.0 개체 라이브러리를 사용하여 Visual Basic .NET에서 Outlook 연락처를 검색하는 방법에 대해 설명합니다. 위의 예에서와 마찬가지로
Namespace 개체의
GetDefaultFolder 메서드가 루트 폴더의 폴더에 액세스합니다.
NameSpace 개체는 기존의 모든 Outlook 폴더에 연결되는 게이트웨이로 생각할 수 있습니다. 다음 절차에서는
GetDefaultFolder 메서드가 연락처 폴더에서 연락처를 검색합니다. 연락처에서는
ContactItem 개체도 함께 사용됩니다.
ContactItem 개체는 연락처 폴더의 연락처를 나타냅니다. 연락처는 개인 연락처나 직장 연락처를 알고 있는 모든 사람을 나타낼 수 있습니다.
- Visual Studio .NET을 시작합니다.
- 파일 메뉴에서 새로 만들기를 클릭하고 프로젝트를 클릭합니다.
- 프로젝트 형식에서 Visual Basic 프로젝트를 선택하고 서식 파일에서 콘솔 응용 프로그램을 클릭합니다. 기본적으로 Module1.vb가 만들어집니다.
- "Microsoft Outlook 11.0 개체 라이브러리"에 참조를 추가합니다. 참조를 추가하려면 다음 단계를 수행합니다.
- 프로젝트 메뉴에서 참조 추가를 클릭합니다.
- COM 탭에서 Microsoft Outlook 11.0 개체 라이브러리를 클릭한 다음 선택을 클릭합니다.
- 참조 추가 대화 상자에서 확인을 클릭합니다. 선택한 라이브러리에 대해 래퍼를 만들 것인지 묻는 메시지가 나타나면 예를 클릭합니다.
- 코드 창에서 기본 코드를 다음 코드로 바꿉니다.
Imports System.Reflection
Imports Outlook = Microsoft.Office.Interop.Outlook
Module Module1
Sub Main()
' Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application
' Get namespace and Contacts folder reference.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
Dim cContacts As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
' Get the first contact from the Contacts folder.
Dim oItems As Outlook.Items = cContacts.Items
Dim oCt As Outlook.ContactItem
oCt = oItems.GetFirst()
' Display some common properties.
Console.WriteLine(oCt.FullName)
Console.WriteLine(oCt.Title)
Console.WriteLine(oCt.Birthday)
Console.WriteLine(oCt.CompanyName)
Console.WriteLine(oCt.Department)
Console.WriteLine(oCt.Body)
Console.WriteLine(oCt.FileAs)
'This next statement will display an Address
'Security warning. For more information, see the
'security information in the article at the end of this
'article titled "What's New in Microsoft Office
'Outlook 2003 for Developers"?
Console.WriteLine(oCt.Email1Address)
Console.WriteLine(oCt.BusinessHomePage)
Console.WriteLine(oCt.MailingAddress)
Console.WriteLine(oCt.BusinessAddress)
Console.WriteLine(oCt.OfficeLocation)
Console.WriteLine(oCt.Subject)
Console.WriteLine(oCt.JobTitle)
' Clean up.
oApp = Nothing
oItems = Nothing
oCt = Nothing
End Sub
End Module
- 사용자 상황에 맞게 코드를 변경합니다.
- F5를 눌러 응용 프로그램을 빌드하고 실행합니다.
- 첫 번째 연락처가 검색되었는지 확인합니다.
결론
Outlook에는 각 용도에 맞게 작업 환경을 쉽게 사용자 지정할 수 있는 여러 가지 개체와 메서드가 있습니다. 일회성 모임이나 반복되는 모임과 같은 다양한 형태의 약속에서부터 연락처 목록 검색 및 처리에 이르기까지 다양한 작업을 수행할 수 있습니다. 이 문서에서는 사용자의 용도에 맞게 조합하여 사용할 수 있는 일부 방법에 대해 살펴보았습니다.
추가 리소스
개발자용 Microsoft Office Outlook 2003의 새로운 기능
Microsoft Outlook COM 추가 기능 개발자를 위한 중요 보안 노트
Microsoft 기술 자료 문서 - 291153: OL2002: Outlook 항목의 메시지 또는 본문에 대한 작업
Microsoft 기술 자료 문서 - 220595: HOWTO: Visual Basic을 사용한 Outlook 자동화
Microsoft 기술 자료 문서 - 291120: OL2002: 다른 프로그램에서 Outlook을 자동화하는 방법
2004/10/20 13:47
간편하게 프로그램으로 제어할 수 있는 것도 있지요~^^
http://daiseuki.info/index.php?pl=38