0

I have configured a basic Postfix setup to send mail using an external smtp relayhost, and resolving locally address mail via /etc/aliases. Sending email works (via the sendmail command) However, when I receive the mail, the To: header is missing; it doesn't show up in the raw email message.

Question: How can I have the To: header show up in the receiving mail?

More details

For example, when I send this from the command line:

echo -e "Subject: test no header\n\nBody message" | sendmail myprivate@email.com

or

echo -e "Subject: test no header\n\nBody message" | sendmail root

with /etc/aliases having a line root: myprivate@email.com

I receive the email in both cases. But in both cases, the To: header is not there.

The raw mail looks like this:

Return-Path: <root@myhost.mydomain.com>
X-Envelope-To: myprivate@email.com
X-Footer: aW5kaWdvbWVkLmNvbQ==
Received: from .....
Received: by ...  
Delivered-To: root@myhost.mydomain.com
Received: by myhost.mydomain.com (Postfix, from userid 0)
    id 70CD8A03; Tue, 12 Jan 2021 14:48:16 +0100 (CET)
Subject: test no header
Message-Id: <20210112134816.70CD8A03@myhost.mydomain.com>
Date: Tue, 12 Jan 2021 14:48:16 +0100 (CET)
From: root <root@myhost.mydomain.com>

Body message

What I already tried:

  • Sending the mail via mailx DOES insert the To: header, e.g. echo -e "Body message" | mailx root -s "Subject: test no header"

  • I already tried configuring always_add_missing_headers = yes in /etc/postfix/main.cf but it doesn't help.

Some relevant parts (I think) from my /etc/postfix/main.cf file:

...
append_dot_mydomain = no
...
# General
myhostname = myhost.mydomain.com
myorigin = myhost.mydomain.com
mydestination = $myhostname localhost.$mydomain localhost myhost
...
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
....
relayhost = mail.something.com:465
Rabarberski
  • 263
  • 1
  • 3
  • 9

1 Answers1

2

You don't need any To: header for messages to be delivered to their destination. Only the SMTP envelope is used for that.

Unlike the mailx tool the bare sendmail command is not a full mail client.

The sendmail command will not create a properly formatted mail message, just the bare minimum SMTP envelope to ensure successful transmission. If you want a properly formatted email message, that's what you need to provide to the sendmail command as (standard) input.

In other words:

You need to supply sendmail with message consisting of headers, each header on a new line with a colon separating the header from the header value, with long headers continuing on the line below and starting with one or more spaces. Then an empty line separating the message headers from the body. Then the message body.

Something like this

To: somebody@example.com
Content-Type: text/plain; charset=us-ascii>
From: me@server.example.com (Hermanb)
Subject:  A very very long 
  subject header spanning multiple lines
Date: Tue, 12 Jan 20121 15:46:24 +0200

test test

More test text
.
Bob
  • 5,805
  • 7
  • 25
  • This is interesting; I hadn't expected what you describe. But things fall into place now; `sendmail`being a low-level mail tool/interface, rather than (also being) a simple email utility. Thanks – Rabarberski Jan 12 '21 at 19:35