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@cyberciti.biz < input.file mail -s 'Uptime Report' you@cyberciti.biz < /tmp/output.txt
Where,
- -s 'Subject' : Specify subject on command line.
- you@cyberciti.biz: 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@cyberciti.biz < /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.cyberciti.biz ### Email photo.png along with a text message read from body.txt ## (cat body.txt; uuencode photo.png photo.png) | mail -s "Subject" user@cyberciti.biz
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop











{ 5 comments… read them below or add one }
Thanks nixCraft…you guys are doing a awesome job..keep it up
Use mail with from and to email IDs
cat /home/user/input.file | mail -s ‘Subject-Here’ -v notify-to@email-id.com — -f from.email-id.com
I wonder if we can specify from email ID while using mutt too?
Hi, thank you for this great tutorial. Just wondering if there’s a pre-requirement for the above to work? I have tried on my Debian Linux box but my emails have not received the sent message. My Linux box is connected to the Internet. It’s just a web server.
You need local smtp (such as Postfix, sendmail) installed. On debian you need to start exim email service.
i need to send mail with multi attach file by commands line, can you help me