但是,裡面的方法隻能用于發送普通電子郵件。如果要發起會議之類的特殊郵件的話,可以使用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

using System;
2

using System.Collections.Generic;
3

using System.Text;
4

using Microsoft.Office.Interop.Outlook;
5
/**/////////////////////
6
/**//* 調用Outlook api 發起會議
7
8
////////////////////
9
namespace 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 = "内容";
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
//發件人的帳号資訊
46
oItem.SendUsingAccount = oApp.Session.Accounts[2];
47
48
//添加必選人
49
Recipient force = oItem.Recipients.Add("[email protected]");
50
force.Type = (int)OlMeetingRecipientType.olRequired;
51
//添加可選人
52
Recipient opt = oItem.Recipients.Add("[email protected]");
53
opt.Type = (int)OlMeetingRecipientType.olOptional;
54
//添加會議發起者
55
Recipient sender = oItem.Recipients.Add("[email protected]");
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
}
83
