C#中調(diào)用Outlook API發(fā)起網(wǎng)絡會議
創(chuàng)建項目后,為它添加.NET引用:“Microsoft.Office.Interop.Outlook"的引用,即可調(diào)用,需要注意的是,在添加的時候,注意一下Office版本號。
在C#調(diào)用Outlook API發(fā)起會議的過程中,遇到了一個問題:
創(chuàng)建完一個約會條目后,找了很久沒找到如何為這一約會指定“發(fā)件人”,后來一想,Window CF 中,查找人員信息有個OutlookSession的東東,
那這Outlook會不會有同樣的方式呢,經(jīng)過測試,還真的找到方法,原來,它的API指定的發(fā)件人是和你機上運行的Outlook的帳戶設置直接相關的。
通過 ApplicationClass.Session.Accounts即可找到您設置的帳戶集合,需要特別特別注意的是,在這里,取某個人員時,集合的索引是從1開始,而不是從0開始。 找到相關的帳戶后,可以通過 AppointmentItem.SendUsingAccount 屬性來指定約會的發(fā)件人。
---但是,如果我不使用Outlook里帳戶設置的帳戶集合,而要指定其它的郵件帳戶來發(fā)送郵件時該怎么弄?到現(xiàn)在也沒有找到或發(fā)現(xiàn)辦法,希望知道的達人們能
下面是測試的代碼,在Win2003+Office 12下運行通過,成功創(chuàng)建會議:
1using System;
2using System.Collections.Generic;
3using System.Text;
4using Microsoft.Office.Interop.Outlook;
5/**/////////////////////
6/**//* 調(diào)用Outlook api 發(fā)起會議
7/* mcjeremy@cnblogs.com
8////////////////////
9namespace OutlookAPI
10{
11 class Program
12 {
13 static void Main(string[] args)
14 {
15 try
16 {
17 ApplicationClass oApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
18
19 //會議是約會的一種
20 AppointmentItem oItem = (AppointmentItem)oApp.CreateItem(OlItemType.olAppointmentItem);
21 oItem.MeetingStatus = OlMeetingStatus.olMeeting;
22
23 oItem.Subject = "主題";
24
25 oItem.Body = "內(nèi)容";
26
27 oItem.Location = "地點";
28
29 //開始時間
30 oItem.Start = DateTime.Now.AddDays(1);
31
32 //結束時間
33 oItem.End = DateTime.Now.AddDays(2);
34
35 //提醒設置
36 oItem.ReminderSet = true;
37 oItem.ReminderMinutesBeforeStart = 5;
38
39 //是否全天事件
40 oItem.AllDayEvent = false;
41
42 oItem.BusyStatus = OlBusyStatus.olBusy;
43
44 //索引從1開始,而不是從0
45 //發(fā)件人的帳號信息
46 oItem.SendUsingAccount = oApp.Session.Accounts[2];
47
48 //添加必選人
49 Recipient force = oItem.Recipients.Add("mailuser2@mailserver.com");
50 force.Type = (int)OlMeetingRecipientType.olRequired;
51 //添加可選人
52 Recipient opt = oItem.Recipients.Add("mailuser3@p.mailserver.com");
53 opt.Type = (int)OlMeetingRecipientType.olOptional;
54 //添加會議發(fā)起者
55 Recipient sender = oItem.Recipients.Add("mailuser1@mailserver.com");
56 sender.Type = (int)OlMeetingRecipientType.olOrganizer;
57
58 oItem.Recipients.ResolveAll();
59
60 //oItem.SaveAs("d:/TEST.MSG", OlSaveAsType.olMSG);
61
62 oItem.Send();
63
64 //MailItem mItem = (MailItem)oApp.CreateItem(OlItemType.olMailItem);
65 //Recipient rTo = mItem.Recipients.Add("****");
66 //rTo.Type = (int)OlMailRecipientType.olTo;
67 //Recipient rCC=mItem.Recipients.Add("****");
68 //rCC.Type = (int)OlMailRecipientType.olCC;
69 //Recipient rBC = mItem.Recipients.Add("****");
70 //rBC.Type = (int)OlMailRecipientType.olBCC;
71
72 Console.WriteLine("OK");
73 }
74 catch (System.Exception ex)
75 {
76 Console.WriteLine(ex.Message);
77 }
78
79 Console.ReadLine();
80 }
81 }
82}
C#中調(diào)用Outlook API發(fā)起網(wǎng)絡會議就為大家介紹到這里。
【編輯推薦】