筆記 | 設定自架 Ghost SMTP
部落格荒廢了好一段時間,近期終於想用手機登入管理介面留下些草稿,突然發現無法登入,登入鈕下方出現了如下的一段訊息
EmailError: Failed to send email. Please check your site configuration and try again.
結論先行,原因是我安裝的 ghost 版本,在首次使用新裝置登入時需要 2FA (二階段驗證),也就是說,除了帳號密碼登入之外,還會有一層驗證機制,而這層驗證機制需要輸入 6 碼驗證碼 (Ghost 站台發給登入者註冊信箱的 mail 會提供)。我當時建置 Ghost 時認為自己不會發送電子報,就忽略了 SMTP 的設定,導致 Ghost 站台不能正常發信,在配置好 SMTP 設定後 (我使用的是 Mailgun,應該也可以用 Gmail 的),從新裝置就能正常登入了。
前一篇文章提到我的 Ghost 是架設在 Zeabur,記錄一下怎麼設定的:
Mailgun 設定
- 在 Mailgun 註冊帳號 (如果還沒有)
- 左側選單 Send > Sending > Domains,點擊 Add New Domain,設定你的網域 (理解上是你的網站)
- 左側選單 Send > Sending > Domain Settings,找到 SMTP credentials,點擊 Add New SMTP User,設置帳號及取得密碼
Ghost 設定
- 登入 Zeabur,選擇建立的 Ghost

- 進入 ghost 服務的環境變數,設定需要的變數

Key | Value |
---|---|
mail__transport | SMTP |
mail__options__service | Mailgun |
mail__options__host | smtp.mailgun.org |
mail__options__port | 587 |
mail__options__secure | false |
mail__options__auth__user | 在 Mailgun 設定的 SMTP Credential 帳號 |
mail__options__auth__pass | 在 Mailgun 設定的 SMTP Credential 密碼 |
- 完成設置後,重啟 Ghost 服務

參考資訊