Change the “From:” address in Unix “mail”

后端 未结 19 2151
萌比男神i
萌比男神i 2020-12-12 14:32

Sending a message from the Unix command line using mail TO_ADDR results in an email from $USER@$HOSTNAME. Is there a way to change the \"From:\" ad

19条回答
  •  青春惊慌失措
    2020-12-12 14:35

    GNU mailutils's 'mail' command doesn't let you do this (easily at least). But If you install 'heirloom-mailx', its mail command (mailx) has the '-r' option to override the default '$USER@$HOSTNAME' from field.

    echo "Hello there" | mail -s "testing" -r sender@company.com recipient@company.com
    

    Works for 'mailx' but not 'mail'.

    $ ls -l /usr/bin/mail
    lrwxrwxrwx 1 root root 22 2010-12-23 08:33 /usr/bin/mail -> /etc/alternatives/mail
    $ ls -l /etc/alternatives/mail
    lrwxrwxrwx 1 root root 23 2010-12-23 08:33 /etc/alternatives/mail -> /usr/bin/heirloom-mailx
    

提交回复
热议问题