Search code examples
phpsymfonyswiftmailersymfony-3.3

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


Over my SYmfony project I have configured the Swiftmailer to use the following email settings:

On config.yml:

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

But when I try to send an email over my via Swiftmailer I get the response:

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

I also tried the following settings:

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

And I try to figure out why without any idea. Do you know why?

Edit 1:

I try to figure out if openssl is installed into php anf I run:

 php -m | grep ssl

And I get response:

openssl

Edit 2:

Also php has openssl support:

enter image description here


Solution

  • In the end I had to use the following config:

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

    I guess that Swiftmailer has specific configuration for gmail.

    (Or because it is pain in the neck to setup with gmail, so swiftmailer developers provided a nice pain-free alias)