How can I change displayed name as sender?

Solution 1:

Don't use mail, there are better command-line MUAs, such as mailx (package bsd-mailx) or mutt.

mailx will do what you want with the -r flag:

echo Test. | mailx -r "Joe Sender <[email protected]>" -s Test [email protected]

You can likewise specify a display name for the recipient, by the way.

The nickname shown in for instance gmail.com comes from the part of the From field that is outside <[email protected]>, so in this example it would be Joe Sender.

Solution 2:

Using mail, you can set the username using the proper syntax, such as echo "Test" | mail -a "From: Someone <[email protected]>" [email protected].