0

I have setup a mail server on ubuntu 16.04 using postfix, dovecot and spamassasin, I am able to login to gmail and apple mail. emails in the form user@mydomain.com works fine, both incoming and outgoing

emails using virtual domains for example user@somecompany.com can only send emails but cannot receive from other hosts. But they can send and receive from each other

Here is my /etc/postfix/main.conf

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
append_dot_mydomain = no

readme_directory = no

smtpd_tls_cert_file=/etc/letsencrypt/live/mydomain.com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/mydomain.com/privkey.pem

smtpd_use_tls=yes

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes

smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mydomain.com
alias_maps = hash:/etc/aliases

alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

emails to the local mailboxes.
virtual_transport = lmtp:unix:private/dovecot-lmtp

virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf

smtp_generic_maps = hash:/etc/postfix/generic

Below is my Dovecot Configuration

auth_mechanisms = plain login
mail_location = maildir:/var/mail/vhosts/%d/%n
mail_privileged_group = mail
namespace inbox {
  inbox = yes
  location = 
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Sent {
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
  mailbox Trash {
    special_use = \Trash
  }
  prefix = 
}
passdb {
  args = /etc/dovecot/dovecot-sql.conf.ext
  driver = sql
}
protocols = imap lmtp pop3
service auth-worker {
  user = vmail
}
service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0666
    user = postfix
  }
  unix_listener auth-userdb {
    mode = 0600
    user = vmail
  }
  user = dovecot
}
service imap-login {
  inet_listener imap {
    port = 0
  }
}
service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    group = postfix
    mode = 0600
    user = postfix
  }
}
ssl = required
ssl_cert = </etc/letsencrypt/live/mydomain.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mydomain.com/privkey.pem
ssl_prefer_server_ciphers = yes
ssl_protocols = !SSLv2 !SSLv3
userdb {
  args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n
  driver = static
}

The output of netstat -ntlp is

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      1264/dovecot    
tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      1264/dovecot    
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1248/mysqld     
tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN      4604/master     
tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      1264/dovecot    
tcp        0      0 127.0.0.1:783           0.0.0.0:*               LISTEN      2660/spamassassin.p
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1237/sshd       
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      4604/master     
tcp6       0      0 :::993                  :::*                    LISTEN      1264/dovecot    
tcp6       0      0 :::995                  :::*                    LISTEN      1264/dovecot    
tcp6       0      0 :::587                  :::*                    LISTEN      4604/master     
tcp6       0      0 :::110                  :::*                    LISTEN      1264/dovecot    
tcp6       0      0 ::1:783                 :::*                    LISTEN      2660/spamassassin.p
tcp6       0      0 :::80                   :::*                    LISTEN      1453/apache2    
tcp6       0      0 :::22                   :::*                    LISTEN      1237/sshd       
tcp6       0      0 :::25                   :::*                    LISTEN      4604/master     
tcp6       0      0 :::443                  :::*                    LISTEN      1453/apache2 

Below is the tail of my log file

Aug  6 11:41:49 abstractclassa postfix/postfix-script[4386]: warning: group or other writable: /usr/lib/postfix/./libpostfix-master.so.1
Aug  6 11:41:49 abstractclassa postfix/postfix-script[4387]: warning: group or other writable: /usr/lib/postfix/./sbin/lmtp
Aug  6 11:41:49 abstractclassa postfix/postfix-script[4388]: warning: group or other writable: /usr/lib/postfix/sbin/./lmtp
Aug  6 11:46:32 abstractclassa dovecot: imap-login: Login: user=<sales@abstractclass.com>, method=PLAIN, rip=168.167.4.2, lip=172.31.33.89, mpid=4431, TLS, session=<ypg$
Aug  6 11:46:37 abstractclassa dovecot: imap-login: Login: user=<ombedzi@abstractclass.com>, method=PLAIN, rip=168.167.4.2, lip=172.31.33.89, mpid=4434, TLS, session=<g$
Aug  6 11:46:38 abstractclassa dovecot: imap-login: Login: user=<malete@abstractclassa.com>, method=PLAIN, rip=168.167.4.2, lip=172.31.33.89, mpid=4435, TLS, session=<i$
Aug  6 11:49:10 abstractclassa dovecot: imap(sales@abstractclass.com): Connection closed in=227 out=4529
Aug  6 11:49:10 abstractclassa dovecot: imap(ombedzi@abstractclass.com): Connection closed in=75 out=1685
Aug  6 11:49:10 abstractclassa dovecot: imap(malete@abstractclassa.com): Connection closed in=75 out=1683
Aug  6 11:49:21 abstractclassa postfix[4476]: Postfix is running with backwards-compatible default settings
Aug  6 11:49:21 abstractclassa postfix[4476]: See http://www.postfix.org/COMPATIBILITY_README.html for details
Aug  6 11:49:21 abstractclassa postfix[4476]: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload"
Aug  6 11:49:21 abstractclassa postfix/master[3765]: terminating on signal 15
Aug  6 11:49:21 abstractclassa postfix[4567]: Postfix is running with backwards-compatible default settings
Aug  6 11:49:21 abstractclassa postfix[4567]: See http://www.postfix.org/COMPATIBILITY_README.html for details
Aug  6 11:49:21 abstractclassa postfix[4567]: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload"
Aug  6 11:49:22 abstractclassa postfix/master[4604]: daemon started -- version 3.1.0, configuration /etc/postfix
Aug  6 11:49:30 abstractclassa dovecot: imap-login: Login: user=<sales@abstractclass.com>, method=PLAIN, rip=168.167.4.2, lip=172.31.33.89, mpid=4611, TLS, session=<9TX$
Aug  6 11:49:37 abstractclassa dovecot: imap-login: Login: user=<ombedzi@abstractclass.com>, method=PLAIN, rip=168.167.4.2, lip=172.31.33.89, mpid=4614, TLS, session=<S$
Aug  6 11:49:37 abstractclassa dovecot: imap-login: Login: user=<malete@abstractclassa.com>, method=PLAIN, rip=168.167.4.2, lip=172.31.33.89, mpid=4615, TLS, session=<M$
Aug  6 11:52:51 abstractclassa dovecot: imap(malete@abstractclassa.com): Connection closed in=380 out=7376
Aug  6 11:52:51 abstractclassa dovecot: imap(sales@abstractclass.com): Connection closed in=1575 out=14486
Aug  6 11:52:51 abstractclassa dovecot: imap(ombedzi@abstractclass.com): Connection closed in=2015 out=31191
  • ""user@somecompany.com can only send emails but cannot receive."" Do you have any log, error message? Is imapd running? What's the output of netstat -ntlp? Have you tried getting email using telnet? – bgtvfr Aug 6 '18 at 11:54
  • I edited the question to include the output of netstat -ntlp and the tail of my log file, telnet works fine – daRula Aug 6 '18 at 12:08
  • Does abstractclassa.com belong to the mysql table listed in /etc/postfix/mysql-virtual-mailbox-domains ? "telnet works fine" -> can you see mailbox content with telnet? – bgtvfr Aug 6 '18 at 13:01
  • my /etc/postfix/mysql-virtual-mailbox-domains queries mysql table looking for the domain hosts = 127.0.0.1 dbname = servermail query = SELECT 1 FROM virtual_domains WHERE name='%s' – daRula Aug 6 '18 at 13:12
  • What's the output of SELECT * FROM virtual_domains ? Is abstractclassa.com (or the domain name you want to receive mail with) listed in it? When you try sending mail to user@somecompany.com, do you have a Delivery Status Notifications ? – bgtvfr Aug 6 '18 at 13:21
0

OK, the mistake was with me really, doing something without proper research, I didn't know that virtual domains you place in the MySQL table have to be actual domains that really exist for it to work

So i used not existent domains and gmail was trying to locate them to deliver the email, but it couldn't find them.

Otherwise my email server works fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.