本文章是由機器翻譯。

Microsoft Office

探索 JavaScript API for Office:範例郵件應用程式

Angela Ch-Hatoun

下載代碼示例

伴隨著這篇文章 MSDN 雜誌第條,"探索 JavaScript API 為辦公室:郵件應用程式"(msdn.microsoft.com/magazine/dn201750)。在這裡,我走過去建設樣例組 IM 郵件應用程式使用該文章中解釋的技術。

從一條消息啟動組 IM

組 IM 郵件應用程式允許您方便地啟動組即時消息會話與寄件者、 收件者或無需離開 Outlook 或 Outlook Web 應用程式,其電子郵件地址包括在所選郵件的正文中的任何人。圖 1 貝琳達選定後的Jeff和Ben和正在準備好開始使用組 IM IM 會話郵件應用程式的收件者為使用者顯示。應用程式窗格中的讀取窗格,以及任何 SMTP 位址 (弗農,Sam 和羅馬) 在郵件正文中的貝琳達要啟動 IM 會話與包括當前郵件的所有收件者的 SMTP 位址。


圖 1 組 IM 郵件應用程式來啟動組聊天會話中選擇郵件收件者

組 IM 郵件應用程式假定 Lync 作為 IM 用戶端,它支援會話初始協定 (SIP) 和命令列的方法來啟動 IM。您可以修改此郵件 app,InstantMessage.js 中, 所示的 JavaScript 檔中的 checkAddress 函數圖 2 (你可以下載在郵件應用程式的原始檔案的完整集 code.msdn.microsoft.com/Mail-apps-for-Outlook-2b20fc16),為不同的 IM 用戶端自訂應用程式。

圖 2 InstantMessage.js JavaScript 檔

var _Item;
var itemEntities;
var myEntities = new Array();
var uniqueNumInRecipientsAndBody=0;
Office.initialize = function () {
  _Item = Office.context.mailbox.item;
  itemEntities = _Item.getEntities();
  $(document).ready(function () {
   initIM();
  }); 
}
var checkedItems;
checkedItems = "";
// This function verifies if the user has checked any of the
// checkboxes for the SMTP addresses, and if so, constructs a hyperlink
// for starting an IM session.
function checkAddress(emailForm)
{
  var anychecked;
  anychecked = 0;
  checkedItems = "im:";
  // See if the e-mail sender address is checked.
if (emailForm.checkbox0.checked == true) {
    checkedItems += "<sip:" + _Item.sender.emailAddress + ">";
    anychecked = 1;
  }
  for (var i=1; i<=uniqueNumInRecipientsAndBody; i++) {
    var tempy;
    // Determine if each checkbox is checked.
// Each checkbox name is a variable depending on value of i.
tempy = "checkbox" + i;
    // Use JavaScript square bracket notation instead of dot notation to access
    // emailForm.tempy.checked, because tempy is a variable.
tempy = emailForm[tempy]["checked"];
    if (tempy)  {
      // If the checkbox is checked, construct an SIP address
      // for that e-mail address.
checkedItems += "<sip:" + myEntities[i-1] + ">";
      anychecked = 1; 
    }
  }
  // Clear the variable if none of the checkboxes is checked.
// UI phrase remains not a hyperlink.
if (anychecked == 0) {
    checkedItems = "";
    document.getElementById("mySpan").innerHTML = "Start an instant message conversation";
  } 
  else {
    // If one or more checkboxes are checked, then turn the UI phrase into a hyperlink.
document.getElementById("mySpan").innerHTML =
      "<A HREF = \"" + checkedItems + "\">Start an IM conversation</A>";
  }    
}
// This function counts the unique number of e-mail addresses.
// The first such count number of array cells in myEntities
// contain the unique e-mail addresses.
function makeMyAddressesUnique (addressArray)
{
  var emailAddress;
  var j=0;
  for (var i in addressArray) {
    emailAddress = addressArray[i];
    // Check if e-mail address is not the same as the sender's address
    // or the current user's address, is new and
    // has not occured in the first i number of cells in addressArray.
if ((emailAddress.toLowerCase() !== _Item.sender.emailAddress.toLowerCase()) &&
      (emailAddress.toLowerCase() !==  
      Office.context.mailbox.userProfile.emailAddress.toLowerCase()) &&
      (emailAddrIsNew (i, emailAddress, addressArray))) {
      myEntities[j] = emailAddress.toLowerCase();
      j++;
    }
    // Otherwise e-mail address already occurred in sender or addressArray, so ignore it.
// The next new e-mail address will overwrite cell j in myEntities.
}
    // Tallied the number of unique addresses in the body.
uniqueNumInRecipientsAndBody = j;   
}
function emailAddrIsNew (index, address, array) {
  var counter = 0;
  while (counter < index) {
    if (address.toLowerCase() === array[counter].toLowerCase()) {
      return (false);
    }
    counter++;
  }
  return (true);
}
function initIM()
{
  var myHTMLString;
  var myCell;
  var tempEntities;
  var toRecipients;
  var ccRecipients;
  var recipientsAddresses = new Array ();
  var recipientsAndBodyAddresses = new Array();
  toRecipients = _Item.to;
  ccRecipients = _Item.cc;
  myHTMLString = "";
  // Assign first the To recipients addresses, followed by
  // the cc recipients addresses.
for (var i=0; i<toRecipients.length; i++) {
    recipientsAddresses[i] = toRecipients[i].emailAddress;
  }
  for (var i=0; i<ccRecipients.length; i++) {
    recipientsAddresses[i+toRecipients.length] = ccRecipients[i].emailAddress;
  }
  recipientsAndBodyAddresses = recipientsAddresses.concat(itemEntities.emailAddresses);
  makeMyAddressesUnique (recipientsAndBodyAddresses);
  myCell = document.getElementById('extensionspace');
  myHTMLString += "<form><span id=\"mySpan\">Start an instant message conversation</span>" +
    " with the following persons:<BR>";
  myHTMLString += "<input type=checkbox name='checkbox0" + "' value='" +
    _Item.sender.emailAddress + "' onClick='checkAddress(this.form)' />" +
    _Item.sender.emailAddress + "<br>";
  for (var i=0; i<uniqueNumInRecipientsAndBody; i++) {
    myHTMLString += "<input type=checkbox name='checkbox" + (i+1) + "' value='" +
      myEntities[i] + "' onClick='checkAddress(this.form)' />" +
      myEntities[i] + "<br>";
    }
    myCell.innerHTML = myHTMLString + "</form>";
}

該方案

同時閱讀一封電子郵件,你想要向前移動一次討論的即時消息的收件者的郵件,或與人的電子郵件地址包含在消息的正文中。 你可以選擇組 IM 郵件應用程式、 選擇中的應用程式窗格收件者或電子郵件從郵寄地址和,無需離開 Outlook,在您的 IM 用戶端啟動組 IM 會話。

此方案假設 Outlook 2013 (或更高版本) 的使用和交流線上或Exchange Server2013年 (或更高版本)。 出席者和其 SMTP 位址也應由 IM 用戶端支援。

嘗試郵件應用程式

按照該檔,"自述為組 IM 郵件 app,"中的說明與附帶的代碼下載 (code.msdn.microsoft.com/Mail-apps-for-Outlook-2b20fc16),下載和安裝您的郵箱的郵件應用程式。 Outlook 啟動這個郵件應用程式的任何電子郵件收件匣中,以便您可以嘗試此郵件應用程式與您在讀取窗格中查看或郵件檢查器的任何消息。 或者,一個更容易控制的測試環境,你可以創建特殊測試電子郵件消息、 包括你自己和幾個其他收件者、 指定的郵件正文中,幾個其他 SMTP 位址和發送郵件。

若要測試,在讀取窗格中打開特殊測試消息和選擇的"組 IM"應用程式按鈕。 應用程式窗格中列出的收件者的電子郵件地址和郵件正文中的 SMTP 位址。 在應用程式窗格中,選擇兩個或多個電子郵件地址並選擇連結"啟動 IM 會話"。IM 用戶端打開 IM 視窗,用來啟動組聊天會話。

本文的其餘部分描述的 XML 清單、 HTML 檔案和 JavaScript 檔組 IM 郵件應用程式。 一路走來,我就會突出顯示興趣的點。

XML 清單

每個郵件應用程式必須定義一個清單,如下為 Office XML 架構的應用程式記錄在 MSDN 庫文章中, **"**架構映射 (辦公室應用程式),"在 bit.ly/13bPpWH。 郵件應用程式清單定義應用程式的下列中繼資料:

  • 識別
  • 地區設定的支援
  • 所需的主機應用程式的能力
  • 表單係數
  • 相應的 HTML 檔案,為每個表單因數 (如果需要) 的
  • 顯示要求
  • 必需的許可權
  • 啟動規則

本節重點介紹了在清單中,Lync IM.xml,感興趣的漸次組 IM 郵件應用程式的特定點。 有關清單的完整清單,請參見圖 3 (你可以下載在郵件應用程式的原始檔案的完整集 (code.msdn.microsoft.com/Mail-apps-for-Outlook-2b20fc16)

圖 3 應用程式的 XML 清單檔

<?xml version="1.0" encoding="utf-8"?>
<OfficeApp xmlns="https://schemas.microsoft.com/office/appforoffice/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MailApp">
  <Id>0DA74E27-C945-47A0-9857-64268DEF6542</Id>
  <Version>1.0</Version>
  <ProviderName>Microsoft</ProviderName>
  <DefaultLocale>EN-US</DefaultLocale>
  <DisplayName DefaultValue="Group IM">
    <Override Locale="FR-FR" Value="Message instantané"/>
  </DisplayName>
  <Description DefaultValue="Start a group instant message session using Lync.">
    <Override Locale="FR-FR" Value="Démarrer un message instantané appel directement à partir de Outlook ou Outlook Web App à l'aide de Lync."/>
  </Description>
  <IconUrl DefaultValue="https://exchangemoe.redmond.corp.microsoft.com/ext/ach/GroupIM/mslync-logo_small.png"/>
  <Capabilities>
    <Capability Name="Mailbox"/>
  </Capabilities>
  <DesktopSettings>
    <!-- Change the following line to specify the web server -->
    <!-- that hosts the HTML file.
-->
    <SourceLocation DefaultValue=
      "https://exchangemoe.redmond.corp.microsoft.com/ext/ach/GroupIM/InstantMessage.htm"/>
    <RequestedHeight>216</RequestedHeight>
  </DesktopSettings>
  <TabletSettings>
    <!-- Change the following line to specify the web server -->
    <!-- that hosts the HTML file.
-->
    <SourceLocation DefaultValue=
      "https://exchangemoe.redmond.corp.microsoft.com/ext/ach/GroupIM/InstantMessage.htm"/>
    <RequestedHeight>180</RequestedHeight>
  </TabletSettings>
  <Permissions>ReadItem</Permissions>
  <Rule xsi:type="ItemIs" ItemType="Message"/>
</OfficeApp>

根項目 OfficeApp 指定命名空間和 app 類型 MailApp,而是按順序包含適用于郵件應用程式的子項目的根項目。 MailApp 擴展 OfficeApp,和其子項目進一步定義的郵件應用程式中繼資料:

<OfficeApp xmlns="https://schemas.microsoft.com/office/appforoffice/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MailApp">

一個唯一的識別碼的 Id 元素指定區分這個應用程式從其他應用程式為辦公室,宿主應用程式的通用唯一識別碼 (UUID):

<Id>0DA74E27-C945-47A0-9857-64268DEF6542</Id>

應用程式標籤顯示名稱元素標識應用程式作為"組 IM"的應用程式欄上。 Outlook 通過在應用程式欄上,顯示的"組 IM"啟動此應用程式,如果在清單中指定的規則符合中所選的專案 (見"啟動規則"一節):

<DisplayName DefaultValue="Group IM">
  <Override Locale="FR-FR" Value="Message instantané"/>
</DisplayName>

地區設定支援 DefaultLocale 元素指定區域性名稱的地區設定,在此案例 EN-US,UI 中的字串的應用程式清單中。 您可以使用重寫子項目來支援 (如"消息 instantané"在前面的示例中的 FR-FR 語言環境名稱) 的地區設定特定的顯示名稱、 說明、 圖示圖像或原始程式碼檔:

<DefaultLocale>EN-US</DefaultLocale>

詳細說明描述元素通常指定應用程式的目的。 預設值屬性對應于指定的 DefaultLocale 元素的地區設定。 你可以使用重寫子項目來為不同的地區設定,如 FR-FR 支援說明:

<Description DefaultValue="Start a group instant message session using Lync.">
  <Override Locale="FR-FR"
    Value="Démarrer un message instantané appel directement
    à partir de Outlook ou Outlook Web App à l'aide de Lync."/>
</Description>

功能功能和能力的元素指定與您的應用程式工作的功能 — — 在此情況下,郵箱的能力。 而不是顯式指定的主機應用程式您的應用程式要求,您可以使用這些元素來告訴為辦公平臺的應用程式如何與匹配的合資格的宿主應用程式可以支援您的應用程式。 支援郵箱功能的應用程式可以成為這個應用程式的宿主:

<Capabilities>
  <Capability Name="Mailbox"/>
</Capabilities>

因為用於辦公室的 JavaScript API 是一個綜合的 API 為辦公室由所有應用程式共用和支援主機應用程式,支援對某些物件或成員不同從主機到主機。 更多的這種情況下會出現的工作窗格的應用程式 (例如,Bindings.addFromPromptAsync)。 為郵件應用程式的一個例子是 Diagnostics.OWAView 屬性,其目的是為在 Outlook Web App 但不是 Outlook 中進行調試。 在這種情況下,您應該確保在使用它之前定義的 API。

設備相關原始程式碼檔和顯示 DesktopSettings 和 TabletSettings 的元素指定這個應用程式可以運行在桌上型電腦和平板形式因素。 您可以使用的 SourceLocation 和 RequestedHeight 的元素指定相同或設備相關的 HTML 原始檔案,並為應用程式顯示高度 (以圖元為單位)。 組 IM 郵件應用程式的桌面和平板電腦的形式因素,使用相同的 HTML 原始程式碼檔,它指定更高的應用程式窗格以桌面比平板電腦。

這是 HTML 檔案的 URL:

https://webserver/GroupIM/InstantMessage.htm

組 IM 應用程式之前,你應當用替換 HTML 檔案的 URL 的 HTML 檔案的實際位置在您的配置:

<DesktopSettings>
  <!-- Change the following line to specify the Web server -->
  <!-- that hosts the HTML file.
-->
  <SourceLocation DefaultValue="https://webserver/GroupIM/InstantMessage.htm"/>
  <RequestedHeight>216</RequestedHeight>
</DesktopSettings>
<TabletSettings>
  <!-- Change the following line to specify the Web server -->
  <!-- that hosts the HTML file.
-->
  <SourceLocation DefaultValue="https://webserver/GroupIM/InstantMessage.htm"/>
  <RequestedHeight>180</RequestedHeight>
</TabletSettings>

許可權許可權元素指定的這個應用程式要求的權限等級。 在這種情況下,組 IM 郵件應用程式需要讀取的專案許可權,因為這款應用程式訪問交流從郵件主題和正文中提取的實體 (SMTP 位址):

<Permissions>ReadItem</Permissions>

啟動規則這個應用程式指定 ItemIs 規則與作為的項類型的消息。 這意味著 Outlook 將顯示組 IM 應用程式欄中,每當使用者在讀取窗格或檢查器中查看一條消息:

<Rule xsi:type="ItemIs" ItemType="Message"/>

請注意有某些類型的郵件不支援郵件的應用程式。 請參見"專案支援啟動"一節 (bit.ly/11n0hNE) 的 MSDN 庫文章,"定義規則,以顯示在 Outlook 2013 年的郵件應用程式"的詳細資訊。

HTML 執行

HTML 檔案中,InstantMessage.htm,指定在應用程式的使用者介面,在應用程式窗格中所顯示。 本節重點介紹幾個的興趣點。 InstantMessage.htm 的完整清單,請參見圖 4 (你可以下載從郵件應用程式的原始檔案的完整集 code.msdn.microsoft.com/Mail-apps-for-Outlook-2b20fc16).

圖 4 InstantMessage.htm 檔

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<style type="text/css">
  .title{
    font-family: arial, sans-serif;
    color: blue;
    font-size: 12pt;
    text-decoration:none;
    font-weight:bold;
  }
  .property{
    font-family:Segoe UI;
    color: black;
    font-size: 10pt;
    text-decoration:none;
  }
  .value{
    font-family:Segoe UI;
    color: gray;
    font-size:  10pt;
    text-decoration:none;
  }
  .valuesmall{
    font-family: Segoe UI;
    color: gray;
    font-size:  8pt;
    text-decoration:none;
  }
</style>
  <title>Send Instant Messages with Lync</title>
  <script type="text/javascript"
    src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>
  <script type="text/javascript"
    src="https://appsforoffice.microsoft.com/lib/1.0/hosted/office.js"></script>
  <script type="text/javascript" src="InstantMessage.js"></script>
</head>
<body>
  <img src='mslync-logo.png' alt='Microsoft Lync'/>
  <div id="extensionspace" style="font-family: 'Segoe UI'; font-size: 10pt"> </div>
</body>
</html>

使用最高可用的互聯網資源管理器模式用於 Office 應用程式需要在用戶端電腦上的 Internet Explorer 9 最低。 使用以下 meta 標記允許您的應用程式的電腦上使用的最高可用的互聯網資源管理器模式,以提供最好的體驗,使用者可以得到:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">

附註:始終將 meta 元素作為子項目的頭元素,除標題外的其他所有元素和所有其他 meta 元素之前。

為應用程式指定 CSS 組 IM 郵件應用程式中所示,控制的視覺設計和佈局該應用程式的 HTML 檔案中指定 CSS 內聯圖 5

圖 5 指定 CSS

<style type="text/css">
  .title{
    font-family: arial, sans-serif;
    color: blue;
    font-size: 12pt;
    text-decoration:none;
    font-weight:bold;
  }
  .property{
    font-family:Segoe UI;
    color: black;
    font-size: 10pt;
    text-decoration:none;
  }
  .value{
    font-family:Segoe UI;
    color: gray;
    font-size:  10pt;
    text-decoration:none;
  }
  .valuesmall{
    font-family: Segoe UI;
    color: gray;
    font-size:  8pt;
    text-decoration:none;
  }
</style>

更多指南,請參閱"為辦公室的樣式的應用程式的指導方針"節 (bit.ly/XEwfED) 的 MSDN 庫文章,"用於 Office 使用者體驗的應用程式設計指南"。

辦公室圖書館包括 JavaScript API JavaScript API 為辦公室,office.js,提供的內容傳遞網路 (CDN) 位置。 總是使用下面的語句來引用 office.js 從該位置:

<script type="text/javascript"
  src="https://appsforoffice.microsoft.com/lib/1.0/hosted/office.js"></script>

此郵件應用程式使用類似的腳本元素來包括其他 JavaScript 庫檔,包括它自己上述的 JavaScript 檔,InstantMessage.js。

JavaScript 執行

看出在上節中描述了此郵件應用程式的啟動規則,這個應用程式是可用的應用程式欄中,每當使用者在讀取窗格或檢查器中查看一條消息。 如果使用者選擇的應用程式,JavaScript 檔 (InstantMessage.js) 顯示的收件者,任何電子郵件地址包含在郵件正文中,從使用者獲取的任何選擇和啟動與所選的人員組 IM 會話。

而不是通過 InstantMessage.js 如何顯示電子郵件地址和獲取使用者的選擇為 IM 散步,本節的其餘部分說明瞭此郵件應用程式如何使用所附的"基本功能的 JavaScript API 為辦公室"部分中列出的功能 MSDN 雜誌 條 (msdn.microsoft.com/en-us/magazine/dn201750)。

初始化和 DOM-Loaded 事件同步到辦公室為每個應用程式必須處理 Office.initialize 事件。 中所示的以下初始化事件處理常式,儘快為辦公室運行庫的應用程式準備就緒,此郵件應用程式獲取選定的使用者並在郵件中存在的所有知名實體的當前消息:

Office.initialize = function () {
  _Item = Office.context.mailbox.item;
  itemEntities = _Item.getEntities();
  $(document).ready(function () {
   initIM();
  }); 
}

這款應用程式持有直到載入 DOM,當它然後調用 initIM 函數來進行顯示應用程式使用者介面的電子郵件地址。

訪問消息屬性 寄件者cc 這個郵件應用程式使用寄件者cc 可用來讓使用者選擇一個或多個郵件寄件者或收件者的消息物件上的屬性。 每個屬性返回一個或多個 EmailAddressDetails 物件、 哪些映射到一個人的每個以及包括該人的 SMTP 位址。

圖 6 顯示的 initIM 函數的獲取電子郵件地址的詳細資訊部分cc 收件者。

圖 6 獲取電子郵件地址詳細資訊

function initIM()
{
  var myHTMLString;
  var myCell;
  var tempEntities;
  var toRecipients;
  var ccRecipients;
  var recipientsAddresses = new Array ();
  var recipientsAndBodyAddresses = new Array();
  toRecipients = _Item.to;
  ccRecipients = _Item.cc;
  myHTMLString = "";
  // Assign first the To recipients addresses, followed by
  // the cc recipients addresses.
for (var i=0; i<toRecipients.length; i++) {
    recipientsAddresses[i] = toRecipients[i].emailAddress;
  }
  for (var i=0; i<ccRecipients.length; i++) {
    recipientsAddresses[i+toRecipients.length] = 
      ccRecipients[i].emailAddress;
  }
...

下面的代碼片斷顯示了的 initIM 函數的可訪問的郵件寄件者位址,並將其顯示在清單中選擇應用程式窗格中的一部分:

myHTMLString +=
  "<form><span id=\"mySpan\">Start an instant message conversation</span>" +
  " with the following persons:<BR>";
myHTMLString += "<input type=checkbox name='checkbox0" + 
  "' value='" +
  _Item.sender.emailAddress + 
  "' onClick='checkAddress(this.form)' />" +
  _Item.sender.emailAddress + "<br>";

訪問 SMTP 位址的郵件正文中的實體作為下面的代碼片斷顯示了獲取完整的郵件主題和正文中的知名實體集的初始化函數的一部分:

Office.initialize = function () {
  _Item = Office.context.mailbox.item;
  itemEntities = _Item.getEntities();
...

請注意 getEntities 函數返回一套完整的知名實體 — — 包括任何 SMTP 位址 — — 那存在於主題或郵件的正文中。 itemEntities.emailAddresses 返回只有一個交流認識到作為 SMTP 位址的字串陣列。 下面的程式碼片段顯示了如何的 initIM 函數結合的收件者電子郵件地址的任何電子郵件地址中的郵件主題或正文,存在一組,然後調用 makeMyAddressesUnique 函數來排除任何等效的 SMTP 位址,稍後為使用者提供一個獨特的選項清單:

recipientsAndBodyAddresses =
  recipientsAddresses.concat(itemEntities.emailAddresses);
makeMyAddressesUnique (recipientsAndBodyAddresses);

訪問獲取使用者的位址到使用者設定檔為了避免將使用者的 SMTP 位址作為一種選擇提供的 IM 會話,makeMyAddressesUnique 函數進行比較在 UserProfile.emailAddress 屬性中存儲的使用者的位址與電子郵件地址。 [圖 7] 顯示該程式碼。

圖 7 比較與使用者的位址的電子郵件地址

// This function counts the unique number of e-mail addresses.
// The first such count number of array cells in
 // myEntities contains the unique e-mail addresses.
function makeMyAddressesUnique (addressArray)
{
  var emailAddress;
  var j=0;
  for (var i in addressArray) {
    emailAddress = addressArray[i];
    // Check if e-mail address is not the same as the sender's address
    // or the current user's address, is new, and
    // has not occurred in the first i number of cells in addressArray.
if ((emailAddress.toLowerCase() !==
      _Item.sender.emailAddress.toLowerCase()) &&
        (emailAddress.toLowerCase() !==
        Office.context.mailbox.userProfile.emailAddress.toLowerCase()) &&
        (emailAddrIsNew (i, emailAddress, addressArray))) {
          myEntities[j] = emailAddress.toLowerCase();
          j++;
    }
    // Otherwise e-mail address occurred in
    // sender or addressArray already, ignore it.
// The next new e-mail address will overwrite cell j in myEntities.
}

IM 用戶端依賴關係請注意這個應用程式假定使用者設置了 IM 用戶端支援 IM 和 SIP 協定,並使用下面的格式啟動 IM 與指定的 SMTP 位址:

im:<sip:user1@host><sip:user2@host>

如前所述,這種 IM 用戶端的一個例子是 Lync。 在 Lync,與前面的命令 IM 為打開視窗的使用者和指定的 SMTP 位址如果使用者已經簽署了到 Lync 或已成立了 Lync,自動登入。 否則,該命令會打開登錄視窗中。

或者,您可以修改此示例以支援不同的 IM 用戶端,並生成相應的命令為該用戶端啟動組 IM 中的 checkAddress 函數。

有關為 Lync 支援的詳細資訊,請參閱 MSDN 庫文章,"從另一個應用中開始 Lync"(bit.ly/ZvbTvc)。

替代手段來啟動

請注意我執行使用只有一個啟動規則 (正在一條消息的選定項) 和 JavaScript API (Message.getEntities 方法和 Entities.emailAddresses 屬性) 以在郵件正文中獲取任何 SMTP 位址。 我就會顯示一個可選的實現來說明正則運算式啟動規則的一個示例,如何獲取正則運算式匹配在應用程式中。

在應用程式清單中,結合現有的 ItemIs 規則使用模式 = 和屬性,與第二條規則將項正文必須包含一個或多個電子郵件地址,如由名為 reg1 的正則運算式過濾:

<Rule xsi:type="RuleCollection" Mode="And">
  <Rule xsi:type="ItemIs" ItemType="Message"/>
  <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="reg1"
    RegExValue="[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,3}"
    PropertyName="BodyAsPlaintext"/>
</Rule>

然後,在 JavaScript 檔中,而不是訪問交換的任何知名實體已從中提取選定的郵件,像這樣:

itemEntities = _Item.getEntities();

你可以使用 Message.getRegExMatches 方法獲取匹配 reg1 的任何電子郵件地址:

myEntities = _Item.getRegExMatches();

修改 makeMyEntitiesUnique 函數來處理 myEntities.reg1 陣列中存儲的電子郵件地址。

兩種方法,使用知名實體被首選,避免任何額外的開銷,在評價試圖啟動郵件應用程式時的正則運算式。無論啟動規則的應用程式清單中指定的類型,交流總是提取任何知名實體從主題或正文所選項目,所以無需額外開銷而招致的實體作為獲取在郵件正文中的任何電子郵件地址。另一方面,如果電子郵件正文是相對較長,並且包含多個電子郵件地址評價啟動規則中的正則運算式的開銷可以是重大的。若要為郵件應用程式的使用者提供令人滿意的體驗,有某些閾值,您應該知道的如果您使用正則運算式。請參閱 MSDN 庫文章,"啟動與用於 Outlook 的郵件應用程式中的資料的範圍"(bit.ly/170WAQf),有關詳細資訊。

Angela Chu-Hatoun  作為一個軟體發展者開始和轉寫為她解釋軟體是如何工作的更大興趣。她 12 年來,一直在辦公室司一個程式師作家和有關為 Outlook 創建的辦公室和其他解決方案的應用程式的開發人員寫。她喜歡讀了有關當前事務、 園藝、 旅遊、 食品和時尚。

衷心感謝以下技術專家對本文的審閱:安德魯薩拉馬托夫 (Microsoft) 和Tim灣 (Microsoft)

Tim灣 2003 年畢業于加州理工學院和工程和應用科學學位。在過去的九年他一直在 Outlook 中的軟體發展人員。他做了大量 Outlook 2013 年以及以前的版本中的 Outlook 物件模型中的郵件應用程式功能。他期待著新功能和改進功能使全球範圍內為客戶。

安德魯薩拉馬托夫生物 tk (或其他會省略掉)