Question

Postfix can send, but not receive external email.

Posted August 4, 2017 7.3k views
Email Ubuntu 16.04

Here is my output for postconf -n:

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
home_mailbox = Maildir/
inet_interfaces = all
inet_protocols = all
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
milter_default_action = accept
milter_protocol = 2
mydestination = $myhostname, mail.mydomain.com, mydomain.com, Mydomain, localhost.localdomain, localhost
myhostname = mail.mydomain.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
virtual_alias_maps = hash:/etc/postfix/virtual

I’m able to send out email to Gmail, etc., without a hitch. But when I try sending an email from my Gmail to my server, it doesn’t work. I don’t get any messages on /var/log/mail.log so I’m not sure what’s going on.

Thanks!

1 comment
  • Do you have PTR records? You can enable it by renaming your droplet to a FQDN format. After that, you should have a PTR displayed under Networking > PTR.

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.

5 answers

Hi @amorimlucas

Is Postfix listening on port 25?

sudo lsof -iTCP -sTCP:LISTEN -P

And is your firewall active, if so, does it allow port 25?

sudo ufw status

This it my ufw status:

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere                  
80                         ALLOW       Anywhere                  
443                        ALLOW       Anywhere                  
2375/tcp                   ALLOW       Anywhere                  
2376/tcp                   ALLOW       Anywhere                  
OpenSSH                    ALLOW       Anywhere                  
Nginx Full                 ALLOW       Anywhere                  
2525/tcp                   ALLOW       Anywhere                  
Postfix                    ALLOW       Anywhere                  
22 (v6)                    ALLOW       Anywhere (v6)             
80 (v6)                    ALLOW       Anywhere (v6)             
443 (v6)                   ALLOW       Anywhere (v6)             
2375/tcp (v6)              ALLOW       Anywhere (v6)             
2376/tcp (v6)              ALLOW       Anywhere (v6)             
OpenSSH (v6)               ALLOW       Anywhere (v6)             
Nginx Full (v6)            ALLOW       Anywhere (v6)             
2525/tcp (v6)              ALLOW       Anywhere (v6)             
Postfix (v6)               ALLOW       Anywhere (v6) 

And I just realized that I had set the master.cf file to listen to port 2525 a few days ago. So port 25 wasn’t being listened to. I set it to listen to port 25, and all the pending mail came in through the mail queue. But strangely none of them went into my mailbox. I wonder if SpamAssassin filtered them?

  • @amorimlucas

    Great. So far so good.
    To see what’s going on, you need to check your logs - first the mail log:

    /var/log/mail.log
    

    And that usually tells if the mail is being handed over to another service, like SA, and then you need to check the logs of that.

This is what I’m getting in /var/log/mail.log:

... postfix/smtpd[3540]: disconnect from mail-vk0-f53.google.com[209.85.213.53] ehlo=2 starttls=1 mail=1 rcpt=1 data=1 quit=1 commands=7
... postfix/smtpd[3540]: connect from mail-vk0-f68.google.com[209.85.213.68]
... postfix/smtpd[3540]: EB462C6788: client=mail-vk0-f68.google.com[209.85.213.68]
... postfix/cleanup[3545]: EB462C6788: message-id=<43F839B3-E2B2-46C9-853D-4A1607DD0EAB@gmail.com>
... postfix/qmgr[3534]: EB462C6788: from=<myemail@gmail.com>, size=2586, nrcpt=1 (queue active)
... postfix/local[3546]: EB462C6788: to=<user@myserver.com>, orig_to=<info@myserver.com>, relay=local, delay=0.09, delays=0.08/0/0/0.01, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION")

Shouldn’t it be delivering to my /Maildir?

Looks like it’s delivering to command: procmail -a “$EXTENSION”

  • @amorimlucas Please click the Reply link or use @ to notify others

    If you’re running other services, which are scanning the mails, then Postfix delivers to those services first (if you’ve made those configurations).
    Try removing all the extra added services, so you just receive mail to Maildir - then start adding services one-by-one.

    • @hansen Strange, I disabled the only two services I was using: Dovecot and SpamAssassin, but it’s still delivering to procmail. I also set up DKIM today, I wonder if that could be it.

      • @amorimlucas
        You cannot just disable the services, you need to make sure Postfix isn’t delivering to them (Dovecot is not tied into Postfix, since it just reads the Maildir, which Postfix can deliver to).
        But looking at your postconf is says this line, which means it’s specified somewhere (probably in main.cf):

        mailbox_command = procmail -a "$EXTENSION"
        
        • @hansen I’m not sure how that line got in there, weird. Commenting it out got it to work. Thanks for your help!

        • @hansen Now I’m getting another error, I wonder if you’ve seen this before:

          worker.1 | sh: 1: /usr/sbin/sendmail: not found
          

          That’s what I get when I try to send an email from my rails app. Its config is:

          config.action_mailer.delivery_method = :sendmail
          config.action_mailer.perform_deliveries = true
          

0

Add email addresses to /etc/postfix/virtual mylocalusername@mydomain.com mylocalusername mylocalusername2@mydomain.com mylocalusernam2

Then run postmap /etc/postfix/virtual

Un-comment the line that reads the following in main.cf.

virtualaliasmaps = hash:/etc/postfix/virtual

Restart postfix

systemctl restart postfix

Also make sure you server is listening on port 25 for incoming mail. Make sure that the firewall has port 25 open.

Submit an Answer