技術文件目前產品線:Fluent SMTP 郵件

如何在 FluentSMTP 中連接 Gmail 或 Google Workspace

更新日期
閱讀時間
約 12 分鐘
來源狀態
generated-draft

本篇說明

本文說明如何透過 FluentSMTP 外掛連接 Gmail 或 Google Workspace 信箱寄送 WordPress 網站郵件,包含在 Google Cloud Console 建立專案、啟用 Gmail API、建立憑證,並將 Client ID 與 Client Secret 貼入 FluentSMTP 完成授權連線的完整流程。

適合誰使用

使用 WordPress 並想以 Gmail 或 Google Workspace 信箱穩定寄送網站郵件的網站管理員

開始前準備

  • 需擁有可存取 Google Cloud Console 的 Google 帳號(Gmail 或 Google Workspace)
  • 已在 WordPress 後台安裝並啟用 FluentSMTP 外掛

教學內容

在 FluentSMTP 選擇 Gmail/Google Workspace 連線

FluentSMTP 可設定多種郵件傳送方式(連線),日後可透過 Mail From 位址切換使用

  1. 從 WordPress 後台左側選單前往 Settings 中的 FluentSMTP,在 Connection Providers 選擇服務供應商

    Fluent SMTP dashboard
    官方文件介面截圖:Fluent SMTP dashboard

  2. 若已設定過其他連線,可在 FluentSMTP NavbarSettings 區點選 + Add Another Connection 按鈕

    +Add Another Connection button
    官方文件介面截圖:+Add Another Connection button

  3. 點選 Gmail/Google Workspace 分頁以連接此供應商

    Google Workspace tab
    官方文件介面截圖:Google Workspace tab

  4. Add Connection 頁面填寫 From EmailFrom Name 等欄位

填寫連線設定欄位說明

啟用「Set the return-path to match the From Email」後,若郵件因收件人問題退信,會寄到 From Email;未啟用則退信訊息可能遺失

Application Client ID 與 Client Secret 須從 Google Cloud Platform 取得,並對應用於此連線的 From Email

  1. 複製頁面上的 Authorized Redirect URL,稍後在 Google Cloud 建立憑證時會用到
  2. 填妥所有必要資訊後,點選 Authentication with Google & Get Access Token 按鈕取得 Access Token
  3. 完成後點選 Save Connection Settings 按鈕,Gmail 或 Google Workspace 即完成與 FluentSMTP 的連接

    Add Connection Page
    官方文件介面截圖:Add Connection Page

在 Google Cloud Console 建立新專案並啟用 Gmail API

首次使用 Google Cloud Console 可能會出現選擇國家與同意服務條款的視窗

Google cloud pop-up page for terms & conditions
官方文件介面截圖:Google cloud pop-up page for terms & conditions

  1. 點選 Select a project 下拉箭頭,於彈出視窗按下右上角的 NEW PROJECT 按鈕

    New project button
    官方文件介面截圖:New project button

  2. 輸入專案名稱(地點為選填),可點 Edit 更改 Project ID,再按 CREATE 按鈕

    project name-location-Create button
    官方文件介面截圖:project name-location-Create button

  3. 建立完成後點選 SELECT PROJECT 按鈕以啟用 Gmail API 服務

    Select created project button
    官方文件介面截圖:Select created project button

  4. 在左側選單點選 APIs & Services 箭頭圖示,再點 Enable APIs & services

    APIs & Services option from the left sidebar
    官方文件介面截圖:APIs & Services option from the left sidebar

    + ENABLE APIs AND SERVICES button
    官方文件介面截圖:+ ENABLE APIs AND SERVICES button

  5. 點選 + ENABLE APIS AND SERVICES 按鈕,於 Google Workspace 分類下選取 Gmail API 分頁
  6. 點選 ENABLE 按鈕啟用 Gmail API,系統會在數秒後跳轉至 Gmail API 儀表板

    ENABLE button
    官方文件介面截圖:ENABLE button

建立憑證(Credentials)

建立憑證共有五個步驟:Credential Type、OAuth consent screen、Scopes、OAuth Client ID、Your Credentials

Scopes 步驟為選填,FluentSMTP 寄信功能不需額外設定,可直接跳過

  1. 點選頁面右上角的 CREATE CREDENTIALS 按鈕

    CREATE CREDENTIALS button
    官方文件介面截圖:CREATE CREDENTIALS button

  2. 在 Credential Type 選擇 GMAIL API,勾選 User data,再按 Next

    Credential Type
    官方文件介面截圖:Credential Type

  3. 在 OAuth consent screen 填寫 App Name、User support email 與 Developer contact information,完成後按 SAVE AND CONTINUE

    OAuth consent screen
    官方文件介面截圖:OAuth consent screen

  4. 在 Scopes 步驟直接點選 SAVE AND CONTINUE 跳過

    Scopes (optional)
    官方文件介面截圖:Scopes (optional)

  5. 在 OAuth Client ID 選擇 Application Type 為 Web Application,輸入 Application 名稱,並貼上先前複製的 Authorized Redirect URL,再按 CREATE

    OAuth Client ID
    官方文件介面截圖:OAuth Client ID

  6. 完成後點選 DONE 按鈕,憑證即建立完成

    Your Credentials
    官方文件介面截圖:Your Credentials

    OAuth Publish App 官方介面截圖
    官方文件介面截圖:OAuth Publish App 官方介面截圖

發佈應用程式並收集憑證

  1. 從左側選單前往 OAuth Consent Screen,再點選 Audience 進入頁面
  2. 在 Publishing Status 的 Testing 區塊下點選 PUBLISH APP 按鈕,若跳出確認視窗則點 CONFIRM

    OAuth Publish App 官方介面截圖
    官方文件介面截圖:OAuth Publish App 官方介面截圖

  3. 前往左側選單的 Credentials,找到建立的專案名稱並點選進入

    OAuth 2.0 Client IDS- Fluent SMTP credentials
    官方文件介面截圖:OAuth 2.0 Client IDS- Fluent SMTP credentials

  4. 複製頁面右側顯示的 Client IDClient Secret 兩組數值,備用於下一步貼到 FluentSMTP

    Get the Client ID & Client Secret
    官方文件介面截圖:Get the Client ID & Client Secret

完成 FluentSMTP 授權連線

  1. 回到 FluentSMTP 的 Add Connection 頁面,貼上先前建立的 Client ID 與 Client Secret
  2. 點選 Authenticate with Google & Get Access Token 按鈕取得驗證

    Pasting the Client ID & Secret under Add connection page of Fluent SMTP settings
    官方文件介面截圖:Pasting the Client ID & Secret under Add connection page of Fluent SMTP settings

  3. 頁面導向 Google 帳號選擇畫面後,選擇要授權存取的 Gmail 或 Google Workspace 帳號

    Choose you gmail account
    官方文件介面截圖:Choose you gmail account

  4. 在核准視窗點選 Continue 按鈕,允許專案存取使用者資訊

    Continue button
    官方文件介面截圖:Continue button

  5. 系統會產生 Access Token,點選 Copy 按鈕複製此權杖

    Copy the Access token
    官方文件介面截圖:Copy the Access token

  6. 將複製的 Access Token 貼回 FluentSMTP 連線設定,再點選 Save Connection Settings 按鈕完成連接

    Finally save connection settings button
    官方文件介面截圖:Finally save connection settings button

金鑰儲存方式與後續建議

Store Application Keys in DB 預設為啟用,官方建議保留此設定,金鑰會以加密格式存於資料庫

也可選擇透過 Application Keys in Config File 方式,在 wp-config.php 中以 FLUENTMAIL_GMAIL_CLIENT_ID 與 FLUENTMAIL_GMAIL_CLIENT_SECRET 定義金鑰

Detail of Gmail/Google Workspace API Settings
官方文件介面截圖:Detail of Gmail/Google Workspace API Settings

建議設定完成後寄送測試郵件,以確認連線設定是否成功

Preview of connected Gmail server
官方文件介面截圖:Preview of connected Gmail server

介面名稱對照

  • Connection Providers:FluentSMTP 中可選擇的郵件服務供應商清單,例如 Gmail/Google Workspace
  • Add Connection:用來新增並設定郵件服務連線資訊的頁面
  • Authorized Redirect URL:需複製並填入 Google Cloud 憑證設定中的授權轉址網址
  • Access Token:完成 Google 授權後產生的驗證權杖,需貼回 FluentSMTP 連線設定
  • OAuth consent screen:Google Cloud 中設定應用程式名稱與聯絡資訊的畫面
  • Store Application Keys in DB:預設啟用的設定,將金鑰加密儲存於資料庫

注意事項

注意

若未啟用「Set the return-path to match the From Email」,因收件人問題產生的退信通知可能會遺失而收不到

注意

Client ID 與 Client Secret 必須對應到用於此連線的 From Email 所屬 Google Cloud 專案

官方來源

還是卡住了?

先把問題問清楚,通常比直接開工單更快。複製下面的結構,補上你的情況後送出。

用 AI 先釐清問題

/ai 我正在閱讀「如何在 FluentSMTP 中連接 Gmail 或 Google Workspace」,目前卡在:

我已嘗試:

我看到的畫面/錯誤訊息:

請用一步一步的方式告訴我下一步。

需要我們實際進入網站調整設定、修改佈景主題或處理資料時,再建立 /task 工單。