How To Use Postfix Without Third Party Relay Service

Posted March 10, 2020 4.7k views
WordPressLAMP StackEmailDigitalOceanFirewallLEMPDigitalOcean Cloud FirewallsUbuntu 18.04Cloud Computing


I want to use postfix as send only smtp without any third party relay such as gmail :-

But many cloud providers block port 25. Is there any way to make work postfix on port 587?

Tried editing postfix configs but not worked.


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
1 answer

Hi @rishi008,

You should be able to easily change the port from 25 to 587. You can follow the article you’ve provided to actually install Postfix.

As soon as you do, can do the following to enable port 587 using Postfix.

Before we start, here is some information that might confuse people if it’s not mentioned. Normally, everyone uses port 25 as it is the default port in emails. As it is extensively used by many, it conveys malware and spam. So most of the ISPs are filtering the emails coming through it.

Port 587 is another submission port as 25. This port ensures that the emails are submitted securely. Thus, most of the ISPs don’t block this port. This definitely reduces the rate of rejected messages on the server.

Now onto the configuration.

Once you have installed Postfix, open your file

vi /etc/postfix/

Fine the below line and remove the # symbol in front of it:

#submission inet n - n - - smtpd

It should look like so

submission inet n - n - - smtpd

After that, we restart the postfix using the below command.

service postfix restart

This will enable port 587 in postfix.


  • Hi @KDSys

    Really appreciate your help.

    Problem is that I had already tried this, but not working. When I click reset password at WordPress admin (or send email using —> echo “This is the body of the email” | mail -s “This is the subject line” youremailaddress), then it says “mail sent successfully” but do not receive mail at receiving end.

    Opened 587 port both at firewall and ufw firewall.

    I had tried with several cloud providers hence sure that configs are not wrong. It is same as mentioned in official tutorial and changes suggested by you.

    Please suggest if there is alternative method.

    Thanks and regards

    • Hi @rishi008,

      Oh, I see, it’s possible your WordPress installation is not configured to use SMTP but phpMail directly. This uses the port 25 and it’s not considered very legit by providers such as gmail, hotmail etc.

      To resolve this, you’ll need to install an SMTP plugin and configure it to use your droplet which has postfix on it. There are a lot of plugins out there which you can use however here is what I’ve used in the past SMTP Plugin.

      Try to install it, configure it and see if the issue will still be experienced.


      • Hi @KDSys

        Problem is that postfix is itself not able to send email. So configuring WordPress to use postfix seems of no use.

        I used this syntax to send mail from ssh terminal:-

        echo “This is the body of the email” | mail -s “This is the subject line” youremailaddress

        Content of tail /var/log/mail.log :-

        Mar 12 14:52:47  postfix/smtp[29754]: connect to[x.x.x.x]:25: Connection timed out
        Mar 12 14:53:17  postfix/smtp[29754]: connect to[x.x.x.x]:25: Connection timed out
        Mar 12 14:53:47  postfix/smtp[29754]: connect to[x.x.x.x]:25: Connection timed out
        Mar 12 14:53:47  postfix/smtp[29754]: DE63645102: to=<>, relay=none, delay=150, delays=0.02/0.01/150/0, dsn=4.4.1, status=deferred (connect to[x.x.x.x]:25: Connection timed out)

        Output of:- netstat -plutn |grep 587

        tcp        0      0 *               LISTEN      29731/master

        Here are some changes made by me in postfix configs:-

        inet_interfaces = loopback-only
        inet_protocols = ipv4

        587      inet  n       -       y       -       -       smtpd
        submission inet n       -       y       -       -       smtp

        Doubts Regarding SMTP plugin?

        What should I enter in these fields:-

        1. SMTP Username
        2. SMTP Password


        • Hi @rishi008,

          I see, however if you take a look at the error message, you can see it’s still trying to use port 25

          Mar 12 14:53:47  postfix/smtp[29754]: connect to[x.x.x.x]:25: Connection timed out

          Having said that, this is not due to a configuration on postfix but on WordPress and how it’s configured. By default WordPress uses 25 port until you have configured the SMTP plugin.

          As for the fields

          • SMTP Username
          • SMTP Password

          One is the Email account and the password for it.