Bash Email Notification – How to Customize ‘You Have New Mail’ Message

bashemailmotdssh

I'm trying to modify the You have new mail message that is shown below MOTD when you login via SSH.
My goal is to make that message more visible (bright color would be great) so it gets my attention when I log in.

Best Answer

In Bash, custom messages can be set with MAILPATH. The man page has this example:

MAILPATH='/var/mail/bfox?"You have mail":~/shell-mail?"$_ has mail!"'

Trying it:

$ export MAILPATH="$MAIL?\"Santa was here.\""
$
$
$
$ 
"Santa was here."

Oh, uh, okay. Must have misread the man page there.

bright color would be great

So we have to smuggle us some color escape codes into the message...

$ esc=$'\e'
$ export MAILPATH="$MAIL?$esc[1;37;44mREAD YOUR MAIL RIGHT NOW$esc[0m"
$ echo $MAILPATH
/var/spool/mail/frostschutz?READ YOUR MAIL RIGHT NOW
$
$
READ YOUR MAIL RIGHT NOW

I don't know how to color things here, just imagine it screaming in bright white blue. Color choices are subject to taste and local terminal color scheme settings.

Also check that MAILPATH was not already in use and MAIL actually has the correct path to use for MAILPATH.

Related Question