2

When sending email on my local machine (echo foo | sendmail $USER), the email contains From: (my-user-name)@(my-machine-name).localdomain.

According to my command line tools my host doesn't seem to have a local domain extension added to any of the various host names macOS allows.

$ grep localdomain /etc/hosts
$ grep localdomain /Library/Preferences/SystemConfiguration/preferences.plist
$ scutil --get ComputerName
(my-machine-name)
$ scutil --get HostName
(my-machine-name)
$ scutil --get LocalHostName
(my-machine-name)
$ hostname -f
(my-machine-name)
$ alias hostname
-bash: alias: hostname: not found

My research shows .localdomain stems from a Postfix update. However the Git log contains only generic messages, and I couldn't glean from the HISTORY file why it was added.

  1. Who has introduced .localdomain, and why?
  2. For which specific uses is it applicable, if any? (eg. should it be used email Message-ID?)
forthrin
  • 2,631
  • See this answer: https://apple.stackexchange.com/a/303411/119271 – Allan Apr 26 '18 at 12:34
  • In the default configuration, running hostname is equivalent to running hostname -f which prints machine_name.local. Check for any alias defined on hostname by running alias hostname. – Nimesh Neema Apr 26 '18 at 12:34
  • Thanks for editing this. What’s the end goal here? Why not set up your sendmail to put a proper fully qualified domain name in place regardless of the local host name? – bmike Apr 26 '18 at 12:54
  • @bmike: It's for generating email headers such as Message-ID when sending email from localhost. Should these have @localhost or @localhost.localdomain? Not that it matters greatly, I just got sort of curious and wanted to go by conventions. – forthrin Apr 26 '18 at 15:05
  • Perfect - hopefully my edits allow the question to exist clearly at the end of the “setup” – bmike Apr 26 '18 at 19:04

1 Answers1

5

There is no email client in your example (besides possibly the echo); sendmail is part of the Mail Transport Agent which on current versions of macOS is by default Postfix. Postfix will set the domain either from the configuration file or failing that some internal value or system call lookup:

$ postconf | grep localdomain
mydomain = localdomain
$ postconf -n | grep "^mydomain"
$ 

This shows that (at least on my system) the mydomain value is localdomain and that that value is not set in /etc/postfix/main.cf. It thus must instead come from an internal value or via some system call. (You could set it to something appropriate in main.cf; many Mail Transport Agents will reject mail from such local domains because spammers, or otherwise score the message as more likely to be spam. This may not be a problem if the email will never reach the Internet.)

$ strings /usr/sbin/postfix | grep localdomain
localdomain
$ cfu 'char buf[254]; gethostname(buf,254); printf("%s\n",buf)'
glide.local
$ 

Shows that postfix could be using localdomain as an internal value, as that string appears in the binary. This is likely given that gethostbyname(3) returns something that is not localdomain on my system (you probably don't have cfu but there are many ways to execute arbitrary system calls). If one downloads the source code for Postfix, there are indeed various references to localdomain:

$ find . -name "*.c" -exec fgrep localdomain {} +
./src/global/mail_addr_find.c:    UPDATE(var_mydomain, "localdomain");
./src/global/mail_addr_find.c:    UPDATE(var_myorigin, "localdomain");
./src/global/mail_addr_find.c:    UPDATE(var_mydest, "localhost.localdomain");
./src/smtp/smtp_map11.c:    UPDATE(var_myhostname, "localhost.localdomain");
./src/smtp/smtp_map11.c:    UPDATE(var_mydomain, "localdomain");
...

So this value is very likely to be set internally by Postfix, and if necessary should be adjusted by editing the configuration.

thrig
  • 1,114
  • Very good answer, all the way down to the hardcoded strings :) postconf gives me the same as you. However, this doesn't explain it root origin. Even a search gives just sporadic clues: https://www.google.com/search?q="localdomain". I remember local mail as having just @localhost before, so supposedly it was added in some macOS update. The reason for the convention is still somewhat unclear. If anyone can shed a light on this it would be appreciated. – forthrin Apr 26 '18 at 15:01
  • google thinks I'm a robot so dunno what that search shows. there's only two references to localdomain in the RFC (6108 and 7123) neither particularly revealing beyond that it exists. I guess if there's a postfix source code repo you could git bisect to see when those strings were added and why? – thrig Apr 26 '18 at 18:08