How to change sender name (not email address) when using the linux mail command for autosending mail?

therobyouknow picture therobyouknow · Jun 30, 2011 · Viewed 112.7k times · Source

Mailbox shows the sender name as "Apache", because the mail I am autosending is being sent from a Perl CGI program. How do I change it to something else?

Answer

sam hocevar picture sam hocevar · Jun 30, 2011

You just need to add a From: header. By default there is none.

echo "Test" | mail -a "From: Someone <[email protected]>" [email protected]

You can add any custom headers using -a:

echo "Test" | mail -a "From: Someone <[email protected]>" \
                   -a "Subject: This is a test" \
                   -a "X-Custom-Header: yes" [email protected]