程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 如何在 C# 中發起會議之類的特殊郵件

如何在 C# 中發起會議之類的特殊郵件

編輯:.NET實例教程

.

從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();
        }
    }
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved