How Do You Send a Multi-Line Email from the Command Prompt Using Mailx on a RHEL Server?

Problem scenario
You want to send more than one line of text as the body of an email. You want to use the command prompt of a RedHat Enterprise Linux server.

You have installed mailx. If you need to do this, run this command: sudo yum -y install mailx

1. Create the multi-line message that you want to send in a file. Call it foobar.txt.
2. Use this command:

cat foobar.txt | mail -s "placeSubjectHere" -r

-replace "placeSubjectHere" with the subject of your email
-replace "" with the email address that you want the email to appear to be from
-replace "" with the destination email address

3. The email should have been sent. You are done.

An Alternative Way To Send Email
Another way to do this is with Python; to learn how to use Python and not install anything else, see this external posting.

Leave a comment

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