Postfix SMTP – Host or Domain Not Found Error

postfixsmtp

I've just installed Postfix on my Ubuntu, on a local network.

On this network, I have an Exchange Server (using domain mail.example.com).
I had a problem sending an email to a local address: adress@example.com:

relay=none, delay=0.01, delays=0.01/0/0/0, dsn=4.3.5, status=deferred 
(Host or domain name not found. Name service error for name=example.com
type=AAAA: Host found but no data record of requested type)

I solved this problem using relay_domain in my Postfix main.cf:

relay_domains = example.com
transport_maps = hash:/etc/postfix/transport

And in my /etc/postfix/transport:

example.com smtp:[mail.example.com]

Now I can send mails on @example.com, and I have tested some majors webmails (Gmail, Yahoo, Hotmail…). It works. But why I got this error on my adresses @example.com? How can I be sure I never find this error on another domain?

My Postfix configuration is:

postconf -n

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
inet_interfaces = all
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
mydestination = SRVWEB, localhost.localdomain, localhost
myhostname = SRVWEB
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
readme_directory = no
recipient_delimiter = +
relay_domains = domain.com
relayhost =
smtp_generic_maps = hash:/etc/postfix/generic
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
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
transport_maps = hash:/etc/postfix/transport

Best Answer

Your server is trying to use IPv6 when sending the mail. Since the mail.example.com doesn't have an AAAA-record (which is the same as an A-record, but for IPv6), that isn't working.

If you want Postfix to never use IPv6, you can change that in the config file, as explained in the postconf(5) man page:

When IPv6 support is enabled via the inet_protocols parameter,  Post-
fix will do DNS type AAAA record lookups.

When  both IPv4 and IPv6 support are enabled, the Postfix SMTP client
will attempt to connect via IPv6 before attempting to use IPv4.

Examples:

inet_protocols = ipv4
inet_protocols = all (DEFAULT)
inet_protocols = ipv6
inet_protocols = ipv4, ipv6

If you want to change it for this domain only, change your transport map to read

example.com smtp-ipv4:[mail.domain.com]