TECHIES WORLD

For Techs.... Techniques.... Technologies....

CpanelEximLinux

How to send email via Linux commandline

This tutorial explains the details to send an email via Linux commandline.

Ensure that sendmail application is installed and working correctly.

To send an email to user@example.com, we can use the following command.

# mail -s “Test” user@example.com

Hit the return key and you will come to a new line. Enter the text “This is a test”. Follow up the text by hitting the return key again. Then hit the key combination of Control+D to continue. The command prompt will ask you if you want to mark a copy of the mail to any other address, hit Control+D again. This command will send out a mail to the email id mentioned with the subject, “Test”.

To add content to the body of the mail we can use the following command.

# echo “This is a test message” | mail -s “Test” user@example.com

To add content of a file to the body of the mail we can use the following command.

# mail -s “Test” user@example.com < /home/test.txt

To add cc (option '-c') and bcc (option '-b') for this mail.

# echo “This is a test message” | mail -s “Test” user@example.com -c user1@example.com -b user2@example.com

Leave a Reply