当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 如何在 C# 中发起会议之类的特殊邮件

ASP.NET
asp.net GridView控件中模板列CheckBox全选、反选、取消
asp.net GridView 删除时弹出确认对话框(包括内容提示)
asp.net DropDownList 三级联动下拉菜单实现代码
asp DataTable添加列和行的三种方法
Asp.net 页面调用javascript变量的值
asp.net 长文章通过设定的行数分页
asp.net 定时间点执行任务的简易解决办法
asp.net 页面延时五秒,跳转到另外的页面
asp.net 动态输出透明gif图片
asp.net DataList与Repeater用法区别
asp.net Javascript获取CheckBoxList的value
asp.net程序在调式和发布之间图片路径问题的解决方法
asp.net下生成英文字符数字验证码的代码
asp.net 页面版文本框智能提示JSCode (升级版)
ASP.NET URL伪静态重写实现方法
ASP.NET 2.0 中Forms安全认证
asp.net 动态添加多个用户控件
asp.net Repeater显示父子表数据,无闪烁
asp.net 无法获取的内部内容,因为该内容不是文本 的解决方法
asp.net GridView排序简单实现

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 108 ::
收藏到网摘: n/a

从C#中调用Outlook中的API,可以发起会议之类的特殊邮件。方法如下:

创建项目后,为它添加.NET引用:“Microsoft.Office.Interop.Outlook“的引用,即可调用,需要注意的是,在添加的时候,注意一下Office版本号。

在调用其API发起会议的过程中,遇到了一个问题:

创建完一个约会条目后,找了很久没找到如何为这一约会指定“发件人”,后来一想,Window CF 中,查找人员信息有个OutlookSession的东东,

那这Outlook会不会有同样的方式呢,经过测试,还真的找到方法,原来,它的API指定的发件人是和你机上运行的Outlook的帐户设置直接相关的。

通过 ApplicationClass.Session.Accounts即可找到您设置的帐户集合,需要特别特别注意的是,在这里,取某个人员时,集合的索引是从1开始,而不是

从0开始。 找到相关的帐户后,可以通过 AppointmentItem.SendUsingAccount 属性来指定约会的发件人。

下面是测试的代码,在WIN2003+OFFICE12下运行通过,成功创建会议:

以下为引用的内容:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Outlook;
/**/////////////////////
/**//* 调用Outlook api 发起会议
/* [email protected]
////////////////////
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 = "主题";
                oItem.Body = "内容";
                oItem.Location = "地点";
                //开始时间 
                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("[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();
        }
    }
}