Swiftmailer Configuration In Symfony

Ok, I’m tired of forgetting this and struggling with mailer errors. I need to write this down somewhere.

Default Symfony configuration for SwiftMailer looks like this in app/config/config.yml:

    transport: "%mailer_transport%"
    host: "%mailer_host%"
    username: "%mailer_user%"
    password: "%mailer_password%"
    spool: { type: memory }

The main problem here is absent parameters for encryption and auth_mode. When you need to create encrypted connection with SMTP server you need to add these parameters in two places:


    smtp mailer_host: smtp.example.org 
    mailer_port: ~ 
    mailer_user: no-reply@example.org 
    mailer_password: * 
    mailer_encryption: ssl 
    mailer_auth_mode: login

And in app/config/config.yml:

    transport: %mailer_transport% 
    host: %mailer_host% 
    port: %mailer_port% 
    username: %mailer_user% 
    encryption: %mailer_encryption% 
    auth_mode: %mailer_auth_mode% 
    password: %mailer_password% 
    spool: { type: memory }

I’m getting myself caught in this trap in every single project I develop on top of Symfony. We need to get better defaults for this shit.

Alex Panshin avatar
About Alex Panshin
Software Engineer from Russia. Interested in PHP, Scala, microservices and Big/Fast Data stuff.
comments powered by HyperComments