How To Send Mail To Multiple Addresses Using (mailx)

In this guide, you’ll learn a couple of ways you can send mail to multiple addresses using mailx. mailx is a utility program for sending and receiving mail.

I assume you already have mailx command, if you don’t already have it installed, use sudo apt install mailutils, once installed, we can get started using mailx.

To send mail to multiple address, you do the following:

echo "My message" | mail -s "My Mail Subject"

or by taking the message from a file (CD into the file directory, and use the following command):

mail -s "My Mail Subject" < textfile.txt

Add Attachment to the Mail

Attachment can be added with the -aswitch:

echo "My Message Body" | mail -s "My Mail Subject" -a /path/to/file

You can also specify a from name address, use the -r option and wrap the name in “<>”, e.g:

echo "My Message Body" | mail -s "My Mail Subject" -r "<>"-a /path/to/file

Let’s spice this up by using alias,add the list of users you want to send the mail to using:

alias mailadresses=""

Then send the mail using:

echo "My message" | mail -s "My Mail Subject" mailaddresses


Comment policy: Respectful and beneficial comments are welcome with full open hands. However, all comments are manually moderated and those that doesn't relate with what the passage is saying or offensive comments would be deleted. Thanks for understanding!

Leave a Reply

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