How to enable port 25 on my Ubuntu server?

Posted December 1, 2015 98.6k views
Ruby on RailsUbuntuEmail

So I am running Spree e-commerce in Rails. When I click on ‘place order’ after I have added items to my cart and proceed to checkout i got this error. (same question as this person)

Errno::ECONNREFUSED in Spree::CheckoutController#update
Connection refused - connect(2) for "localhost" port 25

I believe it has something to do with the email but I am not 100 percent sure. As for spree is defaulted to port 25 as referred to here

I checked my port using

telnet mydroplet'sIPaddress 25

and it said (as expected)

telnet: Unable to connect to remote host: Connection refused

I tried a solution to unblock my port 25 by adding the line below as suggested in another question here.

iptables -I INPUT -p tcp -m tcp --dport 25 -j ACCEPT

and recheck using the same method and still no good.

I even went to setup my firewall using ufw and made sure my port 25 is available by following this tutorial

sudo ufw allow 25/tcp

still no good…


How do I enable my port 25?

I am running Ubuntu Ruby on Rails on 14.04 (Postgres, Nginx, Unicorn).

My IP address is if anyone wants to try my port 25.

1 comment
  • I have also issue with outgoing port 25, I tried every thing as mention in digitalocean’s community but still facing issue and No one answer my ticket from Digitalocean support system,
    How disappointing :(

    root@iMaker-test:~# telnet 25
    telnet: Unable to connect to remote host: Connection timed out

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
8 answers

Same problem here. When I wrote to the support, this is the response I got:


You are unable to send mail as outgoing SMTP traffic is blocked at this time. After 60 days have passed you can request that the SMTP block on your account be lifted at that time.

Please let us know if you have any other questions!”

So that means if I’m migrating a website, particularly a forum, which needs to send user activation and reply notifications, you can’t go live for 60 days. That’s absolute horrible and unacceptable, especially when I have provided a valid credit card info to them at the time of sign up.

Just open SSH to the server and allow it: ufw allow 25

You’ll probably want to install either sendmail or postfix. Probably postfix.

  • I found the solution by installing Postfix and reconfiguring Rails.

    Here is what I did ..

    step 1 -> follow this tutorial on how to install and configure postfix

    step 2 -> when editing the postfix config in /etc/postfix/ make hostname = localhost

    here is my working setting (I have to set it to ‘localhost’ because the default for Spree’s mail configuration is 'localhost’ you can change Spree also but just have to make sure they match one another.)

    myhostname = localhost
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    mydestination = APPNAME, localhost.localdomain, , localhost
    relayhost =
    mynetworks = [::ffff:]/104 [::1]/128
    mailbox_size_limit = 0
    recipient_delimiter = +
    inet_interfaces = localhost
    inet_protocols = all

    step 3 -> Reconfigured Rails application.rb in config folder of Rails by adding this line (i found the solution here)

    config.action_mailer.smtp_settings = { enable_starttls_auto: false  }

    Here is what my application.rb looks like..

    require File.expand_path('../boot', __FILE__)
    require 'rails/all'
    # Require the gems listed in Gemfile, including any gems
    # you've limited to :test, :development, or :production.
    module APPNAME
      class Application < Rails::Application
        config.to_prepare do
          # Load application's model / class decorators
          Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
            Rails.configuration.cache_classes ? require(c) : load(c)
          # Load application's view overrides
          Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c|
            Rails.configuration.cache_classes ? require(c) : load(c)
        config.action_mailer.smtp_settings = { enable_starttls_auto: false  }
        # Settings in config/environments/* take precedence over those specified here.
        # Application configuration should go into files in config/initializers
        # -- all .rb files in that directory are automatically loaded.
        # Set default to the specified zone and make Active Record auto-convert to this zone.
        # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
        # config.time_zone = 'Central Time (US & Canada)'
        # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
        # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
        # config.i18n.default_locale = :de
        # Do not swallow errors in after_commit/after_rollback callbacks.
        config.active_record.raise_in_transactional_callbacks = true

    Thanks @kode54

    by finid
    Postfix is an MTA (Mail Transfer Agent), an application used to send and receive email. In this tutorial, we will install and configure Postfix so that it can be used to send emails by local applications only.


Like many providers, DigitalOcean blocks Port 25 by default, so you would need to configure another port by which to send e-mail (2525 is a common alternative). You would need to configure your app to send mail through this (new )port and ensure that either your mail server or upstream mail server is capable of serving on this port as well (and, of course, open it on the firewall).

  • I did open my firewall to port 2525 by..

    sudo ufw allow 2525/tcp

    and also try this method

    iptables -I INPUT -p tcp -m tcp --dport 2525 -j ACCEPT

    when i check with

    telnet mydroplet'sIPaddress 2525

    I still get connection refused..

    telnet: Unable to connect to remote host: Connection refused

Facing same problem and no apparent solution

+1, this is very upsetting.

Hello all,

It is possible that port 25 is closed for new accounts. This is something we have been doing to reduce spam on our network. Please do not think that we are accusing you of sending spam, it is more that we simply cannot accurately determine who is going to send it.

Stopping spam is a constant fight, so we have implemented some restrictions on newer accounts. To qualify for the ability to send out email, we do require accounts to wait 60 days before we can look into removing the restriction. Once your account has reached 60 days of stable use, please do reach back out to us so we can look into this for you.

Hope that helps!