D
D
Dmitry2021-03-18 21:21:00
linux
Dmitry, 2021-03-18 21:21:00

How to approach the Errno::ECONNREFUSED (Connection refused - connect(2) for "example.com" port 25) error?

Every time I try to send an email on the production server I get this error instead of the sent email:

Errno::ECONNREFUSED (Connection refused - connect(2) for "example.com" port 25)


production.rb:
Rails.application.configure do
  ...
  config.action_mailer.default_url_options = { host: "localhost" }
  config.action_mailer.default_options = { from: '[email protected]' }
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true

  config.action_mailer.smtp_settings = {
    address: "example.com",
  }
end


Installed Postfix to send mail.

Config /etc/postfix/main.cf :
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
append_dot_mydomain = no
readme_directory = no
compatibility_level = 2

# TLS parameters
smtp_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_security_level = may
smtpd_tls_cert_file=/etc/letsencrypt/live/example.com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/example.com/privkey.pem

smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = dsde949-12345.fornex.org
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, example.com, dsde949-12345.fornex.org, localhost.fornex.org, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all


The mailer works:
$ sudo systemctl status postfix.service
● postfix.service - Postfix Mail Transport Agent
Loaded: loaded (/lib/systemd/system/postfix.service; enabled; vendor preset: enabled)
Active: active (exited) since Thu 2021-03-18 18:45:36 CET; 29min ago
Process: 1110 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 1110 (code=exited, status=0/SUCCESS)

[email protected]:~/rails/current$ telnet example.com 25
Trying 123.123.155.190...
telnet: Unable to connect to remote host: Connection refused

[email protected]:~/rails/current$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 xxx.fornex.org ESMTP Postfix (Ubuntu)
...


It can be seen that "telnet example.com 25" does not work, but "telnet localhost 25" does.

If changed to "localhost"
config.action_mailer.smtp_settings = {
    address: "localhost",
}

then I get another error:
OpenSSL::SSL::SSLError (hostname "localhost" does not match the server certificate):


In general, I don’t understand a lot of things in setting up servers. I've been doing this initial deployment for a whole week now. Also, this is my first time deploying a website with an SSL certificate (Let's Encrypt via Certbot). Maybe this is the issue?

Thanks in advance for any insight!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
CityCat4, 2021-03-19
@CityCat4

I don't understand what's going on here? What was banned in google translator? Can't connect to port 25 on example.com for some reason, like no one is listening there (or banned in the firewall)

D
Dmitry, 2021-03-18
@svetozar

The error was fixed by adding:

config.action_mailer.smtp_settings = {
    address: "localhost",
    openssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
  }

There is no error, yes, but letters do not come either.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question