2

From Bash manual and https://unix.stackexchange.com/a/280557/674

'MAILPATH'

A colon-separated list of filenames which the shell periodically checks for new mail .

Each list entry can specify the message that is printed when new mail arrives in the mail file by separating the filename from the message with a '?'. When used in the text of the message, '$_' expands to the name of the current mail file.

Example:

$ MAILCHECK=1 MAILPATH='/tmp/a?New mail in <$_>' bash
bash$ echo test >> /tmp/a
New mail in </tmp/a>

"Mail" doesn't mean the same as emails or instant messages. What does "mail" mean?

Does the content of a mail file consist of one or more than one "mails"? If more than one, how are the mails separated from each other?

What event is considered as the arrival of a new mail?

Is "mail" a concept within a special application, the bash shell, or the OS? There doesn't need a special application for handling (sending and receiving) "mails". Rather the bash shell checks new "mails".

What can we use "mail" for?

  • For communication between multiple users,
  • for inter-processes communication like named pipes,
  • for detecting changes to specific files (this is what I can tell from the example above)?

Thanks.

  • 7
    Mail does mean the same as email. This is for the case that your email is delivered to a file on your workstation. A separate daemon would receive mail and write (append) it to a mail file. – user4556274 Aug 3 '17 at 16:36
  • I think you need to run sendmail for the mail command to work but it seems that you already have it running. You can use programs such as mutt to open /tmp/a mbox: mutt -f /tmp/a – Arkadiusz Drabczyk Aug 3 '17 at 16:37
  • 2
    In the Mbox format, each message begins with a line that starts with the word From and a space. This is how the messages are separated. (Note that a message typically also contains a line that begins with "From:", these lines do not separate messages.) – Johan Myréen Aug 3 '17 at 16:52
  • @JohanMyréen Thanks. What program do you use for receiving mail and writing (appending) it to a mail file, and what program for reading the messages? – Tim Nov 3 '18 at 22:34
10

It used to be more common for every internet-connected host to run its own smtp daemon to accept smtp connections (tcp/25, with no consideration of security) and deliver mail for local users to a file or directory either under their home directory, or in something like /var/spool/mail/${USERNAME} (or, alternately, to blindly relay it to another host if the mail was not addressed to a local user). Various formats were used, but frequently the format was simply the raw mail (including all headers followed by the message body) concatenated in one long file.

The MAILPATH bash variable indicates the location of the mail file as configured in your local smtp daemon. Compare biff utility.

  • Thanks. Does bash provide some commands for us to send, receive and read mails? – Tim Apr 13 '18 at 0:42
  • @Tim, that is more of a separate question. There have been numerous terminal-based mail clients (assuming that's what you mean by "Does bash provide..."), including the basic and appropriately named mail. – user4556274 Apr 13 '18 at 16:12
  • The bash manual mentions mails, so I assume bash provide mail support to some degree, but I am not sure what kind of support bash provides to mails. From your comment, I was wondering if bash just provide a server for mails, and not clients for mails? – Tim Apr 13 '18 at 16:27
  • Thanks. I know this has been a while.In "It used to be more common for every internet-connected host to run its own smtp daemon to accept smtp connections (tcp/25, with no consideration of security) and deliver mail for local users", is the "smtp daemon" a MDA? – Tim Nov 3 '18 at 21:48
  • Does bash take the role of a MUA, via its MAILPATH variable? – Tim Nov 3 '18 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.