Bash echo mail multiple recipients
A classic!
To send an email to multiple recipients using echo
and mail
commands in bash, you can use the following syntax:
echo "Subject: Your email subject" | mail -s "Your email subject" -c "[email protected],[email protected],..." [email protected]
Here's a breakdown of the options:
echo
: This command is used to generate the email body.mail
: This command is used to send the email.-s
: This option specifies the subject of the email.-c
: This option specifies the list of recipients. You can separate multiple recipients with commas.[email protected]
: This is the email address of the sender.
For example, to send an email to [email protected]
and [email protected]
with the subject "Test email", you can use the following command:
echo "Hello, this is a test email." | mail -s "Test email" -c "[email protected],[email protected]" [email protected]
Note that the -c
option is used to specify the list of recipients, and the email addresses are separated by commas. Also, make sure to replace [email protected]
with your actual email address.
Also, you can use mailx
command instead of mail
which is more powerful and flexible.
echo "Subject: Your email subject" | mailx -s "Your email subject" -c "[email protected],[email protected],..." [email protected]
You can also use mutt
command which is a more advanced email client.
echo "Subject: Your email subject" | mutt -s "Your email subject" -c "[email protected],[email protected],..." [email protected]
Make sure to check the manual pages for each command to learn more about their options and usage.