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

后端 未结 19 2163
萌比男神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:55

    None of the above solutions are working for me...

    #!/bin/bash
    
    # Message
    echo "My message" > message.txt
    
    # Mail
    subject="Test"
    mail_header="From: John Smith "
    recipients="recipient@example.com"
    
    #######################################################################
    cat message.txt | mail -s "$subject" -a "$mail_header" -t "$recipients"
    

提交回复
热议问题