title: Errno::EADDRNOTAVAIL: Cannot assign requested address - connect(2) for "mail.domain.de" port 587
body: <p>I have a <code>Rails</code> application hosted over <code>Digitalocean</code> server. I am using <code>email server</code> from my domain provider(<code>checkdomain.de</code>). I set up an email server with the following configurations:</p>
  
  <pre><code>config.action_mailer.smtp_settings = {
  address: "host162.checkdomain.de",
  port: 587,
  domain: &lt;my-domain&gt;,
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: &lt;my-username&gt;,
  password: &lt;my-password&gt;,
  :openssl_verify_mode  =&gt; 'none'
  }
  </code></pre>
  
  <p>I am using <code>sidekiq</code> for my background jobs for sending emails. Sometimes, when I try to send <code>emails</code> I get the following errors:</p>
  
  <pre><code>Errno::EADDRNOTAVAIL: Cannot assign requested address - connect(2) for "host162.checkdomain.de" port 587
  </code></pre>
  
  <p>OR </p>
  
  <pre><code>SocketError: getaddrinfo: Temporary failure in name resolution
  </code></pre>
  
  <p>Following are the <code>sidekiq</code> configurations in my application:</p>
  
  <pre><code>sidekiq_config = { url: ENV['REDIS_URL'], password: ENV['REDIS_PASSWORD'] }
  Sidekiq.configure_server do |config|
    config.redis = sidekiq_config
  end
  
  Sidekiq.configure_client do |config|
    config.redis = sidekiq_config
  end
  </code></pre>
  
  <p>When I try to send emails without using <code>sidekiq</code> I also got the same errors sometimes.  I am very confused about this issue because I am able to send emails successfully sometimes and sometimes this error occurs without changing anything. I contacted <code>digitalocean</code>(server provider) to make sure if all <code>smtp</code> ports are working fine and are not blocked by them.
  I have seen that this might be an issue due to enabling <code>IPV6</code> service over <code>digitalocean</code> which causes <code>smtp</code> to get blocked. I also have no <code>firewalls</code> enabled on my droplet.</p>
  
  <p>For this reason, I have changed configurations of my droplet to prefer <code>IPV4</code> over <code>IPV6</code> for emails. I have uncommented the following line in <code>/etc/gai.conf</code> file and rebooted the system</p>
  
  <pre><code>#precedence ::ffff:0:0/96 100
  </code></pre>
  
  <p>But, sadly this also didn't help. I am now getting confused about what might be an actual issue to this problem. The only thing that I can try is disabling <code>IPV6</code> completely from my droplet manually as <code>digitalocean</code> does not allow this to do automatically. I am not sure if this will really be helpful or might have bad effect on the server because We can't bear a downtime for server or it might affect the domain or may cause the domain inaccessible. Sending <code>emails</code> is the most crucial part of our application currently I can handle it by retrying to send emails if a failure occurs but this is obviously not a good solution there is a possibility that email is not sent even after retrying many times. Please help me :/ </p>