Sending mail from a container

This should be a simple thing, but I cannot configure postfix to properly send email from a container.

I configure /etc/postfix/ to include the FQDN for the variables, such as:
myhostname =
mydestination = $myhostname,,, , localhost

And I configure /etc/mailname to be

But doing a simple mail check using the mail utility, the mail server for the university rejects it because it is receiving a domain of “root@apps-chem.lxd”.

I don’t know how to configure the container to not send as apps-chem.lxd and instead send as

I would love some guidance. Thanks.


Hi This is not related to LXD.

Please post your /etc/postfix/, /etc/hosts, /etc/hostname, /etc/mailname

best regards

Thanks for responding. Given this does not happen on any of our systems that are not containers, I’m very curious about the cause.

Here are the files you requested:


# See /usr/share/postfix/ for a commented, more complete version

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

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

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname,,, , localhost
relayhost =
mynetworks = [::ffff:]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

/etc/hosts: localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts





Can you please ping ? from the container that is !

Please add your hostname hostname + domain name and ip address to your hosts file please !

Also How to you test your email sent ?

ex :
echo “Mail send $(date)” | mail -s “Test mail from $HOSTNAME”

Adding the container IP and hostname+domain name to the container’s /etc/hosts did not fix it. I then added the container IP to the lxd server’s /etc/hosts, and that did not fix it.

I send mail interactively by starting with:
and enter the subject and body when prompted. Works fine for non-container hosts.


I don’t have an explanation, but I wonder if it’s related to the hostname (apps) being different than the container name (apps-chem).

can you tail -f /var/log/mail.* when you do your send test please ?

Do you use a bridge interface for your containers ?

postfix does not now about you container name, only what is name resolution, like hosts file, dns, and postfix conf

Yes my bridge is the standard lxdbr0.

Here’s the output from /var/log/mail.log when trying to mail:

Oct  1 15:46:06 apps-chem postfix/pickup[12363]: 405FE11394B: uid=0 from=<root@apps-chem.lxd>
Oct  1 15:46:06 apps-chem postfix/cleanup[13630]: 405FE11394B: message-id=<>
Oct  1 15:46:06 apps-chem postfix/qmgr[29135]: 405FE11394B: from=<root@apps-chem.lxd>, size=341, nrcpt=1 (queue active)
Oct  1 15:46:06 apps-chem postfix/smtp[13632]: 405FE11394B: host[] said: 450 4.1.8 <root@apps-chem.lxd>: Sender address rejected: Domain not found (in reply to RCPT TO command)
Oct  1 15:46:06 apps-chem postfix/smtp[13632]: 405FE11394B: to=<>,[]:25, delay=0.2, delays=0.09/0.04/0.02/0.05, dsn=4.1.8, status=deferred (host[] said: 450 4.1.8 <root@apps-chem.lxd>: Sender address rejected: Domain not found (in reply to RCPT TO command))

I just can’t figure out how to make it let go of apps-chem.lxd.

Can you please check the /etc/netplan/ directory and show me the file please ?

And by the way did you reboot after changing the hosts file ?

I can’t reboot until off hours.


    version: 2
            dhcp4: true

can you restart postfix ? systemctl restart postfix; systemctl status postfix

Yeah, I’ve done that several times. No effect.

please run hostname ; hostname -f please




hostname -f


lol !!!

Please do hostname -b “the name that you want with your domain”


OMG. Thanks very much.

I guess I need to run hostname as well as change /etc/hostname.

Again, thanks.


It is a pleasure ! Have fun, it should survive reboot !