SwiftMailer如何使用自定义域名的Gmail发送邮件

4
在symfony2.3中,我正在使用swiftmailer。
我有一个Google应用程序的地址,如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个回答

7

从(我猜是)Google应用程序帐户发送的配置与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

请确保将您的完整电子邮件地址以及端口和加密协议包含在内。
我几个月前从这篇文章中得出了解决方案。
另外,一个小提示:它是encryption而不是mailer_encyption。您可以在此处阅读有关Symfony的swiftmailer参数的更多信息

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 服务器。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接