How To Send Mail To Multiple Addresses Using (mailx)

Last Updated on: 

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" firstuser@gmail.com seconduser@microsoft.com thirduser@yahoo.com andsoon@gmail.com

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

					

mail -s "My Mail Subject" firstuser@gmail.com seconduser@microsoft.com < 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 firstuser@email.com seconduser@email.com

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 "<youruser@server.com>"-a /path/to/file firstuser@email.com seconduser@email.com

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

					

alias mailadresses="user@gmail.com user2@gmail.com user3@gmail.com user100@gmail.com"

Then send the mail using:

					

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

Enjoy!

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 *

css.php