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/main.cf to include the FQDN for the variables, such as:
myhostname = apps.chem.umass.edu
mydestination = $myhostname, apps.chem.umass.edu, localhost.chem.umass.edu, , localhost

And I configure /etc/mailname to be apps.chem.umass.edu.

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 apps.chem.umass.edu.

I would love some guidance. Thanks.

John

Hi This is not related to LXD.

Please post your /etc/postfix/main.cf, /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:

/etc/postfix/main.cf

# See /usr/share/postfix/main.cf.dist 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 http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
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 = apps.chem.umass.edu
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, apps.chem.umass.edu, localhost.chem.umass.edu, , 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

/etc/hosts:

127.0.0.1 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

/etc/hostname:

apps

/etc/mailname:

apps.chem.umass.edu

Thanks.

Can you please ping apps.chem.umass.edu ? 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” bob@bob.com

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:
mail john@chem.umass.edu
and enter the subject and body when prompted. Works fine for non-container hosts.

John

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 main.cf 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=<20201001194606.405FE11394B@apps.chem.umass.edu>
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 race-2.oit.umass.edu[128.119.8.35] 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=<john@chem.umass.edu>, relay=race-3.oit.umass.edu[128.119.8.36]:25, delay=0.2, delays=0.09/0.04/0.02/0.05, dsn=4.1.8, status=deferred (host race-3.oit.umass.edu[128.119.8.36] 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.

/etc/netplan/50-cloud-init.yaml:

network:
    version: 2
    ethernets:
        eth0:
            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

Ah!

hostname

apps-chem

hostname -f

apps-chem.lxd

lol !!!

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

1 Like

Fixed.

OMG. Thanks very much.

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

Again, thanks.

John

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