title: Can't send email using Gmail on Heroku
body: <p>I can't get my Rails app to send emails using Gmail. I can send emails on my local development environment but I can't send it from Heroku.
  This is my config file.</p>
  
  <p>application.rb</p>
  
  <pre><code>  config.action_mailer.smtp_settings = {
      :address        =&gt; 'smtp.gmail.com',
      :domain         =&gt; 'gmail',
      :port           =&gt; 587,
      :user_name        =&gt; ENV['GMAIL_USERNAME'],
      :password         =&gt; ENV['GMAIL_PASSWORD'],
      :authentication     =&gt; 'login',
      :enable_starttls_auto =&gt; true
    }
  </code></pre>
  
  <p>I have tried authentication: 'login' and 'plain' but that didn't work either. I have tried putting this config both into application.rb and production.rb and that didn't work. I've tried domain: "my_my_name_on_heroku.com" but that didn't work either. I have also tried 'mail.google.com' but no luck either.
  I have setup environment variables on Heroku with username and password properly (100% sure).
  I have enabled less secure apps to get the application working at <a href="https://myaccount.google.com/lesssecureapps" rel="nofollow noreferrer">https://myaccount.google.com/lesssecureapps</a>. No 2-factor authentication. I have enabled captcha to allow to login from different devices at <a href="http://www.google.com/accounts/DisplayUnlockCaptcha" rel="nofollow noreferrer">http://www.google.com/accounts/DisplayUnlockCaptcha</a> and still no emails are sent.</p>
  
  <p>On Heroku logs I see that it says "Sending email to...", it renders the template fine, no errors whatsoever but I don't receive any emails. I've checked Spam folder as well but no emails there.</p>
  
  <p>production.rb</p>
  
  <pre><code>  config.action_mailer.default_url_options = { host: 'my_app.herokuapp.com' }
    config.action_mailer.perform_caching = false
    config.action_mailer.perform_deliveries = true
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.raise_delivery_errors = false
    config.action_mailer.default :charset =&gt; "utf-8"
  </code></pre>
  
  <p>What am I missing?</p>