title: Rails actionmailer SSL error hostname does not match server cert
body: <p>I am running rails 4.2 and have set up a rake task to send an email but get this error when I run the rake task:</p>
  
  <pre><code>** Invoke send_report_email (first_time)
  ** Invoke environment (first_time)
  ** Execute environment
  ** Execute send_report_email
  production
  rake aborted!
  OpenSSL::SSL::SSLError: hostname "localhost" does not match the server certificate
  /usr/lib/ruby/2.2.0/openssl/ssl.rb:240:in `post_connection_check'
  /usr/lib/ruby/2.2.0/net/smtp.rb:588:in `tlsconnect'
  /usr/lib/ruby/2.2.0/net/smtp.rb:563:in `do_start'
  /usr/lib/ruby/2.2.0/net/smtp.rb:520:in `start'
  /var/lib/gems/2.2.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
  /var/lib/gems/2.2.0/gems/mail-2.6.3/lib/mail/message.rb:252:in `deliver!'
  /var/lib/gems/2.2.0/gems/actionmailer-4.2.3/lib/action_mailer/message_delivery.rb:77:in `deliver_now!'
  /var/lib/gems/2.2.0/gems/actionmailer-4.2.3/lib/action_mailer/message_delivery.rb:95:in `deliver!'
  /path/to/app/lib/tasks/email_tasks.rake:4:in `block in &lt;top (required)&gt;'
  /usr/lib/ruby/2.2.0/rake/task.rb:240:in `call'
  /usr/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
  /usr/lib/ruby/2.2.0/rake/task.rb:235:in `each'
  /usr/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
  /usr/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
  /usr/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
  /usr/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
  /usr/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
  /usr/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
  /usr/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
  /usr/lib/ruby/2.2.0/rake/application.rb:106:in `each'
  /usr/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
  /usr/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
  /usr/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
  /usr/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
  /usr/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
  /usr/lib/ruby/2.2.0/rake/application.rb:75:in `run'
  /usr/bin/rake:33:in `&lt;main&gt;'
  Tasks: TOP =&gt; send_report_email
  </code></pre>
  
  <p>The line <code>production</code> is just me having a <code>put ENV["RAILS_ENV"]</code> in the rake task to make sure it is set to production</p>
  
  <p>my <code>/config/enviroments/production.rb</code></p>
  
  <pre><code>config.action_mailer_default_url_options = {host: "my.host.com"}
    config.action_mailer_smtp_settings = {
      enable_starttls_auto: false,
      domain: 'my.host.com',
      address: "my.host.com",
      openssl_verify_mode: 'none'
    }
  </code></pre>
  
  <p>When I ran <code>apt-get install postfix</code> I configured it also to use <code>my.host.com</code> and not localhost. Where is rails getting that localhost value from?</p>