swiftmailer send email using gmail with custom domain

ε祈祈猫儿з 提交于 2019-12-18 17:38:11

问题


In symfony2.3 I am using swiftmailer.

I have a Google Apps address like myname@abc.com and my normal gmail address myname@gmail.com

When using:

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

the configuration works great and it sends emails from my gmail address but using myname@abc.com as mailer_user with correct password doesn't work.

Any ideas?


回答1:


The configuration for sending from (what I assume is) a Google Apps account differs from a Gmail account. Your swiftmailer parameters should look something like this:

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

Make sure to include your entire email address as well as the port and encryption protocol.

I derived the solution from this article a few months back.

Also, a small note: its encryption not mailer_encyption. You can read more about the swiftmailer parameters for Symfony here.




回答2:


When you create the message in your controller or anywhere, it's there where you put the sender (setFrom method)

// 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')
;

In your configuration file the mailer_user is used only for connecting to the gmail's smtp server.



来源:https://stackoverflow.com/questions/17970096/swiftmailer-send-email-using-gmail-with-custom-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!