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.
hostnameis equivalent to runninghostname -fwhich printsmachine_name.local. Check for any alias defined onhostnameby runningalias hostname. – Nimesh Neema Apr 26 '18 at 12:34Message-IDwhen sending email from localhost. Should these have@localhostor@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