Ailiganon
Ailiganon

Reputation: 21

Connection refused when trying to send mail using postfix

I want to use the mail() function in PHP. In order to do that, I've installed postfix. I am running on Ubuntu 18.04.

My problem is that I can't send mail as I have a "connection refused" output.

In the terminal, I try :


    echo "This is the body of the email" | mail -s "This is the subject line" [email protected]

And I get this output in mail.log


    Jan 11 01:14:39 AiliganonPC postfix/pickup[9411]: 207FE16016CD: uid=0 from=<root@AiliganonPC>
    Jan 11 01:14:39 AiliganonPC postfix/cleanup[12552]: 207FE16016CD: message-id=<[email protected]>
    Jan 11 01:14:39 AiliganonPC postfix/qmgr[9412]: 207FE16016CD: from=<root@AiliganonPC>, size=370, nrcpt=1 (queue active)
    Jan 11 01:14:39 AiliganonPC postfix/smtp[12554]: connect to gmail-smtp-in.l.google.com[2a00:1450:4010:c0e::1a]:25: Network is unreachable
    Jan 11 01:14:39 AiliganonPC postfix/smtp[12554]: connect to gmail-smtp-in.l.google.com[74.125.131.27]:25: Connection refused
    Jan 11 01:14:39 AiliganonPC postfix/smtp[12554]: connect to alt1.gmail-smtp-in.l.google.com[2404:6800:4008:c13::1a]:25: Network is unreachable
    Jan 11 01:14:39 AiliganonPC postfix/smtp[12554]: connect to alt1.gmail-smtp-in.l.google.com[142.250.157.27]:25: Connection refused
    Jan 11 01:14:39 AiliganonPC postfix/smtp[12554]: connect to alt2.gmail-smtp-in.l.google.com[2607:f8b0:400e:c06::1b]:25: Network is unreachable
    Jan 11 01:14:39 AiliganonPC postfix/smtp[12554]: 207FE16016CD: to=<[email protected]>, relay=none, delay=0.28, delays=0.02/0.01/0.24/0, dsn=4.4.1, status=deferred (connect to alt2.gmail-smtp-in.l.google.com[2607:f8b0:400e:c06::1b]:25: Network is unreachable)

Also, the output of the following command:


    telnet alt2.gmail-smtp-in.l.google.com 25

is


    Trying 108.177.98.26...
    Trying 2607:f8b0:400e:c06::1b...
    telnet: Unable to connect to remote host: Network is unreachable

What I've tried :

Verify that my port 25 was opened and not blocked by firewall :


    sudo lsof -i:25


    COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
    master  12899 root   13u  IPv4 4027269      0t0  TCP *:smtp (LISTEN)
    master  12899 root   14u  IPv6 4027270      0t0  TCP *:smtp (LISTEN)

Disable my firewall

I've also tried with a different mail address (not on gmail) and get same output.

In /etc/postfix/main.cf, I've changed inet_protocols from all to ipv4 and then I've pt it back to "all".

Here's the configuration of my file :


    smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
    myhostname = example.com
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    mydestination = $myhostname, ailiganonpc, AiliganonPC, localhost.localdomain, localhost
    relayhost =
    mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
    mailbox_size_limit = 0
    recipient_delimiter = +
    inet_interfaces = all
    inet_protocols = all

Upvotes: 1

Views: 6502

Answers (3)

Todd Merriman
Todd Merriman

Reputation: 117

  1. I have found that AT&T blocks port 25 on connections FROM my host but allows connections TO port 25 on my host. They will remove the block on request.

  2. The rDNS for your IP must be resolvable to your MX. If (for instance) AT&T is your provider, they can add a DNS record on their end that does this.

  3. Some email providers expect to see SPF, DMARC, and DKIM specifications in your domain registration. There are many Internet postings on how to do this.

You can thank spammers for making all this necessary.

Upvotes: 0

kewwwa
kewwwa

Reputation: 137

I bet that your ISP is blocking port 25 as most of ISP do. Depending on your provider, you can unlock this restriction.

Bien à vous,

kewwwa

Upvotes: 0

wingman
wingman

Reputation: 25

Not sure why you're getting the error but here's a couple of troubleshooting tips that might be helpful to solve this.

Your DNS seems to be working but something in your network is causing the problem, can you ping the Google server and is your ISP maybe blocking port 25 for any reason?

What's the output of netstat -tuplen ?

Your postfix seems to be running, have you tried telneting to yourself?

Upvotes: 0

Related Questions