Symfony SwiftmailerBundle:Gmail 发送“530 5.7.0 必须先发出 STARTTLS 命令”

Symfony SwiftmailerBundle: Gmail sends "530 5.7.0 Must issue a STARTTLS command first"

在我的 SYmfony 项目中,我已将 Swiftmailer 配置为使用以下电子邮件设置:

config.yml:

swiftmailer:
    transport: 'smtp'
    host: 'smtp.gmail.com'
    port: '587'
    encryption: 'tls'
    username: 'gmailUser'
    password: 'gmailPasswd'
    auth_mode: 'login'

但是当我尝试通过 Swiftmailer 发送电子邮件时,我收到了回复:

Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. i61sm9367124edc.32 - gsmtp

我也尝试了以下设置:

swiftmailer:
    transport: 'smtp'
    host: 'smtp.gmail.com'
    port: '465'
    encryption: 'ssl'
    username: 'gmailUser'
    password: 'gmailPasswd'
    auth_mode: 'login'

而且我在毫无头绪的情况下试图找出原因。你知道为什么吗?

编辑 1:

我试着弄清楚 openssl 是否安装到 php 和 运行:

 php -m | grep ssl

我得到回复:

openssl

编辑 2:

另外 php 有 openssl 支持:

最后我不得不使用以下配置:

swiftmailer:
    transport: 'gmail'
    username: '%mailer_user%'
    password: '%mailer_password%'

我猜想 Swiftmailer 有针对 gmail 的特定配置。

(或者因为设置 gmail 很麻烦,所以 swiftmailer 开发者提供了一个很好的无痛别名)