For some reason, I was having a huge problem using Gmail's SMTP with Symfony2's Swiftmailer out of the box. With the default configuration Symfony2 throws at you, it makes sense just to plug in your user, password, server, SSL port and go, right? Well it wasn't the case for me. Sometimes it would send the mail, but most of the time Gmail's servers would refuse the connect. Why? Who knows.

This wasn't in the offical documentation and it took me a bit to figure it out, so I thought I'd share.

Swiftmailer actually has a custom mailer transport for gmail! Guess what? Works like a charm. So instead of manually putting every single option in there for Gmail, we'll just change the transport and enter our username and password. DONE!

app/config/parameters.yml

mailer_transport: gmail
mailer_user: youremail@gmail.com
mailer_password: supercoolpassword

app/config/config.yml

# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"

That's it! You don't need port, server, encryption settings or anything. Swiftmailer will handle everything.