You can use the mail command in Unix or Linux to send the contents of a text file as an email. The basic syntax of the mail command is as follows:
mail -s subject recipient_email_address < text_file
-sis used to specify the subject of the email.recipient_email_addressis the email address of the recipient.< text_fileis used to redirect the contents of the text file into the standard input of themailcommand.
Here’s an example of how to send the contents of a file named file.txt as an email:
mail -s "Subject of the email" recipient.com < file.txt
In this example, the contents of the file file.txt will be sent as the body of the email, and the subject of the email will be “Subject of the email”.
Note that the mail command uses the default mail transport agent (MTA) installed on your system to send the email. On many Unix-like systems, the default MTA is sendmail. You may need to configure your MTA to send email if you have not already done so. (getdelmar.com)
Also note that the mail command does not support attachments, so if you need to send a file as an attachment, you will need to use a different method, such as using a script to generate an email with the attachment, or using a command line email client such as mutt.