# Microsoft Graph 整合

{% hint style="success" %}
目前該功能仍處於 **Beta 階段**，由我們的合作夥伴進行驗收與測試，尚未正式發布。不過，若你有實際需求，仍可先行使用以符合現階段情境，並體驗新的驗證方式。
{% endhint %}

Microsoft 已正式宣布，**明年將全面停用以帳號密碼（SMTP Basic Authentication）進行郵件寄送的方式**。這意味著所有仍依賴傳統 SMTP + 帳密寄信的系統，都將面臨中斷風險。

若你的系統仍透過 `smtp.office365.com` 並使用一般使用者帳號密碼發送郵件，這個模式即將失效。你必須提前完成替換，改用 **Microsoft Graph API + Azure App Registration** 的現代化安全架構。

以下是完整的遷移步驟，協助你在 Azure 中建立應用程式註冊並取得必要的 API 資訊用於 FIRST LINE。

***

### 一、在 Azure 建立應用程式註冊（App Registration）

這一步建立一個「專用應用程式身分」，未來你的系統會以這個身分向 Microsoft Graph 認證、取得寄信權限。

#### 1. 建立 App Registration

1. 登入 **Azure Portal**
2. 前往 **Azure Active Directory → App registrations**
3. 點選 **New registration**
4. 設定：
   * *Name*: 你的應用程式名稱（例：Mail Sender App）
   * *Supported account types*:\
     選擇「Accounts in this organizational directory only」
5. 按下 **Register**

#### 2. 設定寄信權限（Mail.Send）

1. 在你的 App 中進入 **API Permissions**
2. 點選 **Add a permission**
3. 選擇 **Microsoft Graph**
4. 選擇 **Application permissions**（不是 Delegated）
5. 找到 **Mail.Send** 並勾選
6. 按下 **Add permissions**
7. 最後執行 **Grant admin consent**
   * 這將允許此 App 能以組織名義寄信

#### 3. 建立 Client Secret（用來讓系統取得 Token）

1. 進入 **Certificates & secrets**
2. 點選 **New client secret**
3. 設定描述與有效期限
4. 建立後立即複製「Value」
   * **這是你的系統用來取得 Graph API Token 的唯一機會**

***

### 二、你將需要的三個金鑰資訊

從 Azure App Registration 的 Overview 與 Secrets 中，你會拿到：

* **Client ID (Application ID)**
* **Tenant ID**
* **Client Secret**

你的系統將以這三個值執行 OAuth 2.0 Client Credentials Flow，請至 FIRST LINE 對應的信箱帳號貼上即可測試。

***
