【问题标题】:swiftmailer send email using gmail with custom domainswiftmailer 使用带有自定义域的 gmail 发送电子邮件
【发布时间】:2016-10-18 19:50:54
【问题描述】:

在 symfony2.3 中我使用的是 swiftmailer。

我有一个像 myname@abc.com 这样的 Google Apps 地址和我的普通 gmail 地址 myname@gmail.com

使用时:

mailer_transport:  smtp
mailer_encryption: ssl
auth_mode:         login
mailer_host:       smtp.gmail.com
mailer_user:       myname
mailer_password:   pymass

配置效果很好,它从我的 gmail 地址发送电子邮件,但使用 myname@abc.com 作为 mailer_user 并使用正确的密码不起作用。

有什么想法吗?

【问题讨论】:

    标签: symfony swiftmailer


    【解决方案1】:

    从(我假设是)Google Apps 帐户发送的配置与 Gmail 帐户不同。您的 swiftmailer 参数应如下所示:

    mailer_transport:  smtp
    mailer_host:       smtp.gmail.com
    mailer_user:       myname@abc.com
    mailer_password:   pymass
    auth_mode:         login
    port:              587
    encryption:        tls
    

    确保包含您的整个电子邮件地址以及端口和加密协议。

    几个月前我从this article 得到了解决方案。

    另外,请注意:它的encryption 不是mailer_encyption。您可以阅读有关 Symfony here 的 swiftmailer 参数的更多信息。

    【讨论】:

      【解决方案2】:

      当您在控制器或任何地方创建消息时,它就在您放置发件人的位置(setFrom 方法)

      // Create a message
      $message = Swift_Message::newInstance('Wonderful Subject')
        ->setFrom(array('john@doe.com' => 'John Doe'))
        ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
        ->setBody('Here is the message itself')
      ;
      

      在您的配置文件中,mailer_user 仅用于连接到 gmail 的 smtp 服务器。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-08
        • 1970-01-01
        • 2016-11-03
        • 2016-06-03
        • 2021-03-26
        相关资源
        最近更新 更多