The plain text file /etc/mailname is used by the Mail Transfer Agent (i.e. mail server) to know its own hostname.
Debian policy says:
If your package needs to know what hostname to use on (for example) outgoing news and mail messages which are generated locally, you should use the file /etc/mailname. It will contain the portion after the username and @ (at) sign for email addresses of users on the machine (followed by a newline).
Different MTAs may define the hostname differently. This page has been created in the hope that it can be used to document which MTA does it which way, and to reach consensus so that all MTAs can converge.
For the rest of this document mailname will mean the contents of the file /etc/mailname which is a single line with a fully qualified domain name inside.
What does /etc/mailname do?
Policy talks about mailname being "hostname to use on outgoing news and mail messages". This seems to suggest it is supposed to be used for qualifying the From (envelope and header) and using it to qualify recipients does not seem to be supported by policy. (This is how I would interpret policy as well -- Manoj)
However there is also need for something to qualify recipients. A mail sent with:
To: firstname.lastname@example.org Cc: ametzler
should go out with
To: email@example.com Cc: ametzler@<some sane value>
Usually this is taken care of by MTA configuration, however (LOCAL_RELAY, stickyhost, and LUSER_RELAY come to mind for sendmail)
MTA list (by source package name)
Maintainers, please comment here what your package does with /etc/mailname. Please note that were are addressing the sid/unstable version of your package here.
What we would like to know is whether the message generated by
echo foo || sendmail bar
will end up at
foo@<contents of /etc/mailname> (option A)
foo@<local fqdn> (option B)
See the following bug reports for the problems that we currently have:
Failing to come up with something better exim4 (and mutt) use mailname to qualify recipients and therefore exim4 makes mailname a local domain. If people don't want that, they delete it from the list in the debconf dialog.
mailname is not implicitely made a local domain. It is listed explicitely in dc_other_hostnames, where users can easily remove it from in the Debconf dialog. When upgrading existing installations mailname is automatically added once to dc_other_hostnames. On fresh installations mailname is the default value of dc_other_hostnames.
If the visible, rewritten domain name for local users is a local domain (which is the case when it is also the mailname), a special router takes care that the smarthost still works.
Jon Fonseca: /etc/mailname is used to set/get the hostname of the relay STMP server during package onfiguration via debconf, and then write it into /etc/esmtprc. (FYI, smtp just relays all email received from standard input to a relay SMTP server, or to procmail for local delivery.)
Exim (i.e. exim 3.x) doesn't read /etc/mailname at all. When you configure it, it prompts you for what it calls the "visible name" of the system. This is stored in /etc/mailname, and also used in a few places in the exim config file.
One place it's used in the config file is for qualify_domain which is used to qualify recipient addresses.
So normally on a system with exim installed, the value in /etc/mailname is the one that's used to qualify unqualified addresses, but changing /etc/mailname won't have any effect on exim.
Postfix sets myorigin=/etc/mailname. Myorigin is appended (with an @) to any bare name in any address field. During (re)configure, if /etc/mailname exists, it is used as the default value for myorigin in debconf dialogs. Changing it from the default results in postinst rewriting /etc/mailname to the new value.
The exim 4 team observes that postfix behaves basicaly identically to exim4. It makes mailname local by default. If people don't want that, they delete it from the list in the debconf dialog.
John Goerzen has said in 280207 that postfix chooses option A.
slrn uses the content of /etc/mailname as FQDN in address in the From: field of Usenet postings or e‐mails.
When installing the package, the debconf question shared/mailname is used to prompt for the content of /etc/mailname.
In a debconf dialog, ssmtp asks the user to input the name of the system. If there is no input, the default value is hostname --fqdn.
?XMail uses virtual domains. During debconf initial configuration the user is asked an default domain. That domain is used.
In the future /etc/mailname can be used as a default domain if so is decided here.