Howto: Send The Content Of a Text File Using mail Command In Unix / Linux

I‘d like to send an email with the content of a text file using mail command in Unix / Linux operating system. How do I do it?

mail command (also mailx command) is an intelligent mail processing system under Unix and Linux. You need to use the following syntax to send an email using mail command:

mail -s 'Subject-Here' you@sxi.io < input.file
mail -s 'Uptime Report' you@sxi.io < /tmp/output.txt

Where,

  • -s ‘Subject’ : Specify subject on command line.
  • you@sxi.io: To email user.
  • /tmp/output.txt : Send the content of /tmp/output.txt file using mail command.

Send an email as attachment from Unix command line

Either can use the mutt command or uuencode command as described below:

### Attach /tmp/filelist.tar.gz and read the content of a text using /tmp/body.txt ###
mutt -s "Backup status" -a /tmp/filelist.tar.gz you@sxi.io < /tmp/body.txt

OR

### Attach /tmp/list.tar.gz and and send it  ###
uuencode /tmp/list.tar.gz /tmp/list.tar.gz | mailx -s "Reports" user@eu.corp.sxi.io
 
### Email photo.png along with a text message read from body.txt ##
(cat body.txt; uuencode photo.png photo.png) | mail -s "Subject" user@sxi.io

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts