33

I know you can use write to send a message to a currently logged in user, but how do you leave a message for a user who is not logged in? The solution I have seen is modify the motd, but that will be displayed to all users. How can I leave a message for individual users to read when they login?

styfle
  • 433
  • 1
  • 4
  • 7

2 Answers2

35

You can use the mail command to send a message to user jdoe like this:

mail -s "The subject goes here" jdoe

You will enter an interactive environment where you can type your message (mail body). Type Control-D in the beginning of a line to end the message and send it (you will be asked for an optional CC recipient - just hit enter if you don't want one).

You can also do:

mail -s "The subject goes here" jdoe < textfile

or

echo "John, please don't forget our meeting" | mail -s "Reminder" jdoe

The next time jdoe logs in, he will receive a notification like "You have new mail" and he must type mail to read it (perhaps this is a drawback if the user doesn't know he must do this).

Baldrick
  • 9,497
  • 2
  • 17
  • 8
  • This is exactly what I was looking for! Now is there a way to show how many new messages there are without opening `mail`? I'm reading the man page and I don't see a way to do that. I also can't make a bash script that pushes 'q' for me as far as I know. – styfle Sep 24 '11 at 04:30
  • I noticed that when I login, it says 'You have mail' so that is already solved. But in case anyone is wondering, you can use a script like `echo "q" | mail` to see how many messages you have. – styfle Sep 24 '11 at 05:13
  • Note that the mentioned notification is issued by the shell and can be turned off. Supposing you use Bash, see `MAIL`, `MAILCHECK` and `MAILPATH` in the man to know what you can expect. – manatwork Sep 24 '11 at 11:08
  • 1
    You can also run biff to monitor the mailbox. – casualunixer Sep 25 '11 at 00:56
  • this didn't work. I sent a mail to a local user and logged in to that user but didn't receive any mail. – Necktwi Jul 08 '17 at 07:33
  • I have configured `postfix` and `dovecot` on my server with pam authentication. do they interfere with local mail system? – Necktwi Jul 08 '17 at 08:09
-5

Try wall, http://linux.die.net/man/1/wall Maybe that will do the trick?

  • 4
    This is pretty much the opposite of what he wants. He wants a command that leaves a message for a specific, logged out user; wall shows a message to all users currently logged in – Michael Mrozek Jul 01 '12 at 01:44