天天看點

C#中調用Outlook API 發起會議

  但是,裡面的方法隻能用于發送普通電子郵件。如果要發起會議之類的特殊郵件的話,可以使用Outlook 自身的API。

  建立項目後,為它添加.NET引用:“Microsoft.Office.Interop.Outlook"的引用,即可調用,需要注意的是,在添加的時候,注意一下OFFICE版本号。

  在調用其API發起會議的過程中,遇到了一個問題:

  建立完一個約會條目後,找了很久沒找到如何為這一約會指定“發件人”,後來一想,Window CF 中,查找人員資訊有個OutlookSession的東東,

  那這Outlook會不會有同樣的方式呢,經過測試,還真的找到方法,原來,它的API指定的發件人是和你機上運作的Outlook的帳戶設定直接相關的。

  通過 ApplicationClass.Session.Accounts即可找到您設定的帳戶集合,需要特别特别注意的是,在這裡,取某個人員時,集合的索引是從1開始,而不是

  從0開始。 找到相關的帳戶後,可以通過 AppointmentItem.SendUsingAccount 屬性來指定約會的發件人。

 ---但是,如果我不使用Outlook裡帳戶設定的帳戶集合,而要指定其它的郵件帳戶來發送郵件時該怎麼弄?到現在也沒有找到或發現辦法,希望知道的達人們能

  指點一下門路,拜謝先~~~~

   下面是測試的代碼,在WIN2003+OFFICE12下運作通過,成功建立會議:

 1

C#中調用Outlook API 發起會議

using System;

 2

C#中調用Outlook API 發起會議

using System.Collections.Generic;

 3

C#中調用Outlook API 發起會議

using System.Text;

 4

C#中調用Outlook API 發起會議

using Microsoft.Office.Interop.Outlook;

 5

C#中調用Outlook API 發起會議
C#中調用Outlook API 發起會議

/**/////////////////////

 6

C#中調用Outlook API 發起會議
C#中調用Outlook API 發起會議

/**//* 調用Outlook api 發起會議

 7

C#中調用Outlook API 發起會議

/* [email protected]

 8

C#中調用Outlook API 發起會議

////////////////////

 9

C#中調用Outlook API 發起會議

namespace OutlookAPI

10

C#中調用Outlook API 發起會議

{

11

C#中調用Outlook API 發起會議

    class Program

12

C#中調用Outlook API 發起會議

    {

13

C#中調用Outlook API 發起會議

        static void Main(string[] args)

14

C#中調用Outlook API 發起會議

        {

15

C#中調用Outlook API 發起會議

            try

16

C#中調用Outlook API 發起會議

            {

17

C#中調用Outlook API 發起會議

                ApplicationClass oApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();

18

C#中調用Outlook API 發起會議

19

C#中調用Outlook API 發起會議

                //會議是約會的一種

20

C#中調用Outlook API 發起會議

                AppointmentItem oItem = (AppointmentItem)oApp.CreateItem(OlItemType.olAppointmentItem);

21

C#中調用Outlook API 發起會議

                oItem.MeetingStatus = OlMeetingStatus.olMeeting;

22

C#中調用Outlook API 發起會議

23

C#中調用Outlook API 發起會議

                oItem.Subject = "主題";

24

C#中調用Outlook API 發起會議

25

C#中調用Outlook API 發起會議

                oItem.Body = "内容";

26

C#中調用Outlook API 發起會議

27

C#中調用Outlook API 發起會議

                oItem.Location = "地點";

28

C#中調用Outlook API 發起會議

29

C#中調用Outlook API 發起會議

                //開始時間 

30

C#中調用Outlook API 發起會議

                oItem.Start = DateTime.Now.AddDays(1);

31

C#中調用Outlook API 發起會議

32

C#中調用Outlook API 發起會議

                //結束時間

33

C#中調用Outlook API 發起會議

                oItem.End = DateTime.Now.AddDays(2);

34

C#中調用Outlook API 發起會議

35

C#中調用Outlook API 發起會議

                //提醒設定

36

C#中調用Outlook API 發起會議

                oItem.ReminderSet = true;

37

C#中調用Outlook API 發起會議

                oItem.ReminderMinutesBeforeStart = 5;

38

C#中調用Outlook API 發起會議

39

C#中調用Outlook API 發起會議

                //是否全天事件

40

C#中調用Outlook API 發起會議

                oItem.AllDayEvent = false;

41

C#中調用Outlook API 發起會議

42

C#中調用Outlook API 發起會議

                oItem.BusyStatus = OlBusyStatus.olBusy;                

43

C#中調用Outlook API 發起會議

44

C#中調用Outlook API 發起會議

                //索引從1開始,而不是從0

45

C#中調用Outlook API 發起會議

                //發件人的帳号資訊

46

C#中調用Outlook API 發起會議

                oItem.SendUsingAccount = oApp.Session.Accounts[2];               

47

C#中調用Outlook API 發起會議

48

C#中調用Outlook API 發起會議

                //添加必選人

49

C#中調用Outlook API 發起會議

                Recipient force = oItem.Recipients.Add("[email protected]");

50

C#中調用Outlook API 發起會議

                force.Type = (int)OlMeetingRecipientType.olRequired;

51

C#中調用Outlook API 發起會議

                //添加可選人

52

C#中調用Outlook API 發起會議

                Recipient opt = oItem.Recipients.Add("[email protected]");

53

C#中調用Outlook API 發起會議

                opt.Type = (int)OlMeetingRecipientType.olOptional;

54

C#中調用Outlook API 發起會議

                //添加會議發起者

55

C#中調用Outlook API 發起會議

                Recipient sender = oItem.Recipients.Add("[email protected]");

56

C#中調用Outlook API 發起會議

                sender.Type = (int)OlMeetingRecipientType.olOrganizer;                    

57

C#中調用Outlook API 發起會議

58

C#中調用Outlook API 發起會議

                oItem.Recipients.ResolveAll();

59

C#中調用Outlook API 發起會議

60

C#中調用Outlook API 發起會議

                //oItem.SaveAs("d:/TEST.MSG", OlSaveAsType.olMSG);

61

C#中調用Outlook API 發起會議

62

C#中調用Outlook API 發起會議

                oItem.Send();

63

C#中調用Outlook API 發起會議

64

C#中調用Outlook API 發起會議

                //MailItem mItem = (MailItem)oApp.CreateItem(OlItemType.olMailItem);

65

C#中調用Outlook API 發起會議

                //Recipient rTo = mItem.Recipients.Add("****");

66

C#中調用Outlook API 發起會議

                //rTo.Type = (int)OlMailRecipientType.olTo;

67

C#中調用Outlook API 發起會議

                //Recipient rCC=mItem.Recipients.Add("****");

68

C#中調用Outlook API 發起會議

                //rCC.Type = (int)OlMailRecipientType.olCC;

69

C#中調用Outlook API 發起會議

                //Recipient rBC = mItem.Recipients.Add("****");

70

C#中調用Outlook API 發起會議

                //rBC.Type = (int)OlMailRecipientType.olBCC;

71

C#中調用Outlook API 發起會議

72

C#中調用Outlook API 發起會議

                Console.WriteLine("OK");

73

C#中調用Outlook API 發起會議

            }

74

C#中調用Outlook API 發起會議

            catch (System.Exception ex)

75

C#中調用Outlook API 發起會議

76

C#中調用Outlook API 發起會議

                Console.WriteLine(ex.Message);

77

C#中調用Outlook API 發起會議

78

C#中調用Outlook API 發起會議

79

C#中調用Outlook API 發起會議

            Console.ReadLine();

80

C#中調用Outlook API 發起會議

        }

81

C#中調用Outlook API 發起會議

    }

82

C#中調用Outlook API 發起會議

}

83

C#中調用Outlook API 發起會議

繼續閱讀