4

I'm trying to configure Postfix to only send (not receive) emails. I have followed this guide, but I didn't change my hostname to match my domain, because if I can avoid it, I would like to do it.

So, after trying a lot, I keep receiving emails with the hostname after the @, and it's quite frustrating, because I have replaced all the $myhostname variable occurrences in the /etc/postfix/main.cf file with the domain name, but it's as if Postfix doesn't like it and continues sending emails with the hostname attached as domain. Here's my main.cf file:

# 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 = example.com 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 = example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = example.com
mydestination = example.com, localhost.example.com, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all

What am I doing wrong? Do I need to tweak any other thing? Thanks in advance.

amedina
  • 141

3 Answers3

6

The program mail from the package mailutils is adding the domain which then calls sendmail from the package postfix. By default, mail adds the shell variable HOSTNAME as the sender domain before calling sendmail. Either change HOSTNAME or edit /etc/mailutils.conf and add program mail { address { email-domain sender.domain.my ; } }.

Both sendmail and mail can be used to send an email. sendmail will add the domain listed in /etc/mailname if the sender does not already have a domain. As described above, mail will add the sender domain, overriding the sendmail configuration.

Note that HOSTNAME is set by /etc/hostname while sendmail uses /etc/mailname.

To aid debugging, run tail -f /var/log/syslog. Also note, to finish an email in sendmail enter a line containing single period while to end an email in mail enter the EOF character \<ctrl\>D.

See also Changing default domain in mailutils

dbagnara
  • 161
1

Edit /etc/mailname to have a single line, with your domain, and ending with a newline, e.g.:

example.com

Then edit /etc/postfix/main.cf to uncomment the line

#myorigin = /etc/mailname

rendering it as

myorigin = /etc/mailname
vidarlo
  • 23,497
0

A possible answer is in /etc/hosts. There are 2 lines:

127.0.1.1       hostname.domain_name  hostname
192.168.0.47    hostname.domain_name  hostname

Delete the "hostname", and the lines become:

127.0.1.1      domain_name  hostname
192.168.0.47   domain_name  hostname

It works!