How Do You Change The “From” Address in an Email Sent via the Mail Command on Linux?

Problem scenario
You want Linux to send out an email with a alias email address in the "From" field. You are using the mail command on a Linux server. You want to customize the "from" address in the emails that you send. What do you do to choose your own "from" email address (e.g., jdoe@myowndomain.com) in the email that is sent out?

Solution

Prerequisites
You need to have mailx installed. If you are using a Red Had derivative, use this command: sudo yum -y install mailx

Procedures
Use this:

echo "payLoad of Message" | mail -s "placeSubjectHere" -r email@from.com destiny@destination.com

-replace "payload of Message" with the message you want to send
-replace "placeSubjectHere" with the subject of your email
-replace "email@from.com" with the email address that you want the email to appear to be from
-replace "destiny@destination.com" with the destination email address

Leave a comment

Your email address will not be published. Required fields are marked *