C#中調用Outlook API 發起會議

來源:互聯網
上載者:User

  在我上一篇博文中曾提到了 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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.