当前位置: 首页 > 图文教程 > .Net技术 > C# > C#:C#发起邮件会议
在发邮件的时候,如果想发起会议怎么办呢?今天就跟大家分享一个非常实用的方法哦!
创建项目后,为它添加.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/*machiatto_na@163.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];
//添加必选人
Recipient force = oItem.Recipients.Add("[email protected]");
force.Type = (int)OlMeetingRecipientType.olRequired;
//添加可选人
Recipient opt = oItem.Recipients.Add("[email protected]");
opt.Type = (int)OlMeetingRecipientType.olOptional;
//添加会议发起者
Recipient sender = oItem.Recipients.Add("[email protected]");
sender.Type = (int)OlMeetingRecipientType.olOrganizer;
oItem.Recipients.ResolveAll();
//oItem.SaveAs("d:/TEST.MSG", OlSaveAsType.olMSG);
oItem.Send();
//MailItem mItem = (MailItem)oApp.CreateItem(OlItemType.olMailItem);
//Recipient rTo = mItem.Recipients.Add("****");
//rTo.Type = (int)OlMailRecipientType.olTo;
//Recipient rCC=mItem.Recipients.Add("****");
//rCC.Type = (int)OlMailRecipientType.olCC;
//Recipient rBC = mItem.Recipients.Add("****");
//rBC.Type = (int)OlMailRecipientType.olBCC;
Console.WriteLine("OK");
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
}
评论 (0) All