swiftmailer使用gmail和自定义域发送电子邮件

时间:2013-07-31 12:13:34

标签: symfony swiftmailer

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

我有一个Google Apps地址,例如myname@abc.com和我正常的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并使用正确的密码不起作用。

有什么想法吗?

2 个答案:

答案 0 :(得分:7)

从(我假设的)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参数的更多信息。

答案 1 :(得分:0)

当您在控制器或任何地方创建消息时,它就是您放置发件人的位置(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服务器。

相关问题