在 Symfony 5.3 專案中,我使用 Mailer (..\Symfony\Component\Mailer\MailerInterface) 發送郵件。對于開發,我需要使用作曲家的“symfony/google-mailer”并將其設定在 .env.local 中。假設用戶名是“[email protected]”,密碼是“0000”。
在 .env.local 我指定
MAILER_USER='[email protected]'
MAILER_PASSWORD='0000'
MAILER_DSN=gmail://MAILER_USER:MAILER_PASSWORD@default
這導致錯誤
Failed to authenticate on SMTP server with username "MAILER_USER" using the following authenticators: "LOGIN", "PLAIN", "XOAUTH2". Authenticator "LOGIN" returned "Symfony\Component\Mailer\Exception\TransportException: Expected response code "235" but got code "535", with message "535-5.7.8 Username and Password not accepted.
如檔案中所述,我將用戶名(“@”)中的一個特殊字符更改為它的 URL 編碼形式,例如
MAILER_USER='[email protected]'
然后導致錯誤
Email "[email protected]" does not comply with addr-spec of RFC 2822.
(顯然 URL 編碼沒有像預期的那樣作業(因為它沒有被反轉?))我試圖在 services.yaml 的引數中加載環境變數并使用引數代替 - 但這也導致了第一個錯誤。
如果我將身份驗證資訊直接寫入 MAILER_DSN env var,它就可以正常作業,沒有問題,例如
MAILER_DSN=gmail://[email protected]:0000@default
所以這似乎是一個語法問題,我無法從檔案中弄清楚。任何提示?
uj5u.com熱心網友回復:
您應該洗掉單引號,并且需要將其他 env 變數中使用的 env 變數與 ${} sic
[email protected]
MAILER_PASSWORD=0000
MAILER_DSN=gmail://${MAILER_USER}:${MAILER_PASSWORD}@default
結果:
$_SERVER['MAILER_DSN'] = "gmail://[email protected]:0000@default"
uj5u.com熱心網友回復:
.env :
MAILER_DSN=smtp://username:[email protected]
您必須在 google 引數(安全)中啟用對應用程式的訪問。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/343632.html
