设为首页收藏本站language 语言切换
查看: 1723|回复: 0
收起左侧

如何在 C# 中发起会议之类的特殊邮件

[复制链接]
发表于 2010-2-25 10:51:47 | 显示全部楼层 |阅读模式
<p >从C#中调用Outlook中的API,可以发起会议之类的特殊邮件。方法如下:<p >创建项目后,为它添加.NET引用:“Microsoft.Office.Interop.Outlook"的引用,即可调用,需要注意的是,在添加的时候,注意一下Office版本号。<p >在调用其API发起会议的过程中,遇到了一个问题:<p >创建完一个约会条目后,找了很久没找到如何为这一约会指定“发件人”,后来一想,Window CF 中,查找人员信息有个OutlookSession的东东,<p >那这Outlook会不会有同样的方式呢,经过测试,还真的找到方法,原来,它的API指定的发件人是和你机上运行的Outlook的帐户设置直接相关的。<p >通过 ApplicationClass.Session.Accounts即可找到您设置的帐户集合,需要特别特别注意的是,在这里,取某个人员时,集合的索引是从1开始,而不是<p >从0开始。 找到相关的帐户后,可以通过 AppointmentItem.SendUsingAccount 属性来指定约会的发件人。<p >下面是测试的代码,在WIN2003+OFFICE12下运行通过,成功创建会议:<p ><CENTER><ccid_nobr><table width="400" border="1" cellspacing="0" cellpadding="2"  bordercolorlight = "black" bordercolordark = "#FFFFFF" align="center"><tr><td bgcolor="e6e6e6" class="code" ><pre><ccid_code>using System;using System.Collections.Generic;using System.Text;using Microsoft.Office.Interop.Outlook;/**//////////////////////**//* 调用Outlook api 发起会议/* mcjeremy@cnblogs.com////////////////////namespace OutlookAPI{   class Program    {       static void Main(string[] args)       {            try            {                ApplicationClass oApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();                //会议是约会的一种                AppointmentItem oItem = (AppointmentItem)oApp.CreateItem(OlItemType.olAppointmentItem);                oItem.MeetingStatus = OlMeetingStatus.olMeeting;                oItem.Subject = &quot;主题&quot;;                oItem.Body = &quot;内容&quot;;                oItem.Location = &quot;地点&quot;;                //开始时间                 oItem.Start = DateTime.Now.AddDays(1);                //结束时间                oItem.End = DateTime.Now.AddDays(2);                //提醒设置                oItem.ReminderSet = true;                oItem.ReminderMinutesBeforeStart = 5;                //是否全天事件                oItem.AllDayEvent = false;                oItem.BusyStatus = OlBusyStatus.olBusy;                                //索引从1开始,而不是从0                //发件人的帐号信息                oItem.SendUsingAccount = oApp.Session.Accounts[2];                               //添加必选人                Recipient force = oItem.Recipients.Add(&quot;mailuser2@mailserver.com&quot;);                force.Type = (int)OlMeetingRecipientType.olRequired;                //添加可选人                Recipient opt = oItem.Recipients.Add(&quot;mailuser3@p.mailserver.com&quot;);                opt.Type = (int)OlMeetingRecipientType.olOptional;                //添加会议发起者                Recipient sender = oItem.Recipients.Add(&quot;mailuser1@mailserver.com&quot;);                sender.Type = (int)OlMeetingRecipientType.olOrganizer;                                 oItem.Recipients.ResolveAll();                //oItem.SaveAs(&quot;d:/TEST.MSG&quot;, OlSaveAsType.olMSG);                oItem.Send();                //MailItem mItem = (MailItem)oApp.CreateItem(OlItemType.olMailItem);                //Recipient rTo = mItem.Recipients.Add(&quot;****&quot;);                //rTo.Type = (int)OlMailRecipientType.olTo;                //Recipient rCC=mItem.Recipients.Add(&quot;****&quot;);                //rCC.Type = (int)OlMailRecipientType.olCC;                //Recipient rBC = mItem.Recipients.Add(&quot;****&quot;);                //rBC.Type = (int)OlMailRecipientType.olBCC;               Console.WriteLine(&quot;OK&quot;);            }            catch (System.Exception ex)            {                Console.WriteLine(ex.Message);            }            Console.ReadLine();        }    }}</ccid_code></pre></td></tr></table></ccid_nobr></CENTER><p ><p align="right">                                 <p align="center"></p></p>
您需要登录后才可以回帖 登录 | 论坛注册

本版积分规则

QQ|Archiver|手机版|小黑屋|sitemap|鸿鹄论坛 ( 京ICP备14027439号 )  

GMT+8, 2025-4-10 15:54 , Processed in 0.073278 second(s), 24 queries , Redis On.  

  Powered by Discuz!

  © 2001-2025 HH010.COM

快速回复 返回顶部 返回列表