2

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.

7
  • 1
    How are you sending mail? In particular, if you are using the sendmail command, you are doing it wrong.
    – fkraiem
    Mar 31, 2019 at 16:36
  • 1
    By the way, it is also wrong for you to set myhostname to example.com if your hostname isn't actually example.com. That is, if I don't reach your machine when I type ping example.com.
    – fkraiem
    Mar 31, 2019 at 16:39
  • No, I'm sending the email with this command: echo "This is the body of the email" | mail -s "This is the subject line" [email protected]
    – amedina
    Mar 31, 2019 at 16:39
  • @fkraiem It's an example, in my main.cf I have my authentic registered domain.
    – amedina
    Mar 31, 2019 at 16:41
  • 1
    The proper place to set your hostname is really /etc/hostname (and also /etc/mailname). And if you want to send mail with a different envelope address you can use for example mailx with the -r flag.
    – fkraiem
    Mar 31, 2019 at 16:50

3 Answers 3

3

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

5
  • 2
    So how does this answer the question? Jul 14, 2022 at 11:49
  • I am trying to differentiate between the postfix settings and the mailutils settings. The question doesn't specify what program is used to send the email but a later comment shows that send is being used. I have attempted to highlight the difference between sendmail and mail, and the way each program determines the email domain, which is the issue raised in the question. I'm sorry if I am in error.
    – dbagnara
    Jul 14, 2022 at 12:52
  • I suggest you to edit your answer to give first the answer and afterwards, the justification. As your answer is written, it is difficult to follow. Something like: 'It depends on the software you use to send mail. For this software do that. Justification:... Jul 15, 2022 at 7:22
  • Thanks @Marc Vanhoomissen your feedback appreciated.
    – dbagnara
    Jul 16, 2022 at 22:31
  • +1 - (Personally, I think it answered the question.) And they do mention they are using mail in the OP. This would explain why they see email sending as "user@hostname" / no fqdn.
    – B. Shea
    Dec 30, 2022 at 16:45
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
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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .