title: Rails 6.1.4.1 : certificate verify failed (unable to get local issuer certificate) (OpenSSL::SSL::SSLError)
body: <p>Rails/Ruby/OpenSSL will not let me send out emails, why?</p>
  <p><strong>Test in the console:</strong></p>
  <pre><code>irb(main):001:0&gt; @webmessage = Webmessage.new(subject: &quot;Hi there&quot;, body: &quot;Bye now.&quot;, email: &quot;me@me.com&quot;, firstname: &quot;Me&quot;)
  =&gt; #&lt;Webmessage:0x000055bee43fa1d0 id: nil, subject: &quot;Hi there&quot;, body: &quot;Bye now.&quot;, email: &quot;me@me.com&quot;, firstname: &quot;Me&quot;&gt;
  
  irb(main):002:0&gt; ApplicationMailer.with(webmessage: @webmessage).email_webmessage.deliver_now
    Rendered application_mailer/email_webmessage.html.erb within layouts/mailer (Duration: 3.2ms | Allocations: 810)
    Rendered layout layouts/mailer.html.erb (Duration: 4.3ms | Allocations: 1044)
  Delivered mail 614243a5a9582_9b0ab4874e5@host.mail (52.1ms)
  /home/user/.rbenv/versions/3.0.1/lib/ruby/3.0.0/net/protocol.rb:46:in `connect_nonblock': SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate) (OpenSSL::SSL::SSLError)
  </code></pre>
  <p><strong>Resulting error</strong>:</p>
  <p>&quot;SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate) (OpenSSL::SSL::SSLError)&quot;</p>
  <p><strong>My cert paths:</strong></p>
  <pre><code>$ echo $SSL_CERT_DIR
  /etc/ssl/certs
  
  $ echo $SSL_CERT_FILE
  /etc/ssl/certs/ca-certificates.crt
  </code></pre>
  <p><strong>My environment:</strong></p>
  <ul>
  <li>Rails 6.1.4.1</li>
  <li>Ruby 3.0.1p64</li>
  <li>OpenSSL 1.1.1f</li>
  </ul>
  <p>EDIT: This establishes a working connection:</p>
  <pre><code>$ openssl s_client -connect example.com:443 -CAfile /etc/ssl/certs/ca-certificates.crt
  
  
  irb(main):001:0&gt; require 'open-uri'
  =&gt; true
  
  irb(main):002:0&gt; p open(URI.open('https://google.com'))
  #&lt;File:/tmp/open-uri20210915-4444-phdsb&gt;
  =&gt; #&lt;File:/tmp/open-uri20210915-4444-phdsb&gt;
  </code></pre>