在我上一篇博文中曾提到了 SharePoint 中调用传出电子邮件中的邮件服务器及地址发送邮件
但是,里面的方法只能用于发送普通电子邮件。如果要发起会议之类的特殊邮件的话,可以使用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下运行通过,成功创建会议:
1using System;
2using System.Collections.Generic;
3using System.Text;
4using Microsoft.Office.Interop.Outlook;
5////////////////////
6/* 调用Outlook api 发起会议
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 = "内容";
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("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 //添加会议发起者
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}
83
2using System.Collections.Generic;
3using System.Text;
4using Microsoft.Office.Interop.Outlook;
5////////////////////
6/* 调用Outlook api 发起会议
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 = "内容";
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("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 //添加会议发起者
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}
83