media file explorer download upload index folder image licenses menu widget Play Pause profile-settings more dots-two-horizontal dots-two-vertical more-vertical pending google-plus hangouts facebook instagram whatsapp spotify telegram twitter vine renren rss youtube twitch vimeo flickr dribble behance deviantart 500px steam github soundcloud skype reddit linkedin lastfm delicious stackoverflow pinterest xing flattr foursquare yelp World

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" 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!