If you need to send an email with a text file (or binary file) as attachment using shell script or command prompt in Unix or Linux; try mutt - a terminal-based e-mail client for Unix-like systems.
Mutt is a small but very powerful text based program for reading electronic mail under UNIX /Linux operating systems, including support for color terminals, MIME, and a threaded sorting mode.
Please note that mutt is a pure MUA and cannot send e-mail without proper email server . You need a working Mail Transfer Agent (MTA) such as sendmail or postfix. I am assuming that you have a working email server in your office.
How do I install mutt email client?
If mutt is not installed, use the apt-get or yum or up2date commands as follows (you must login as a root user). Debian / Ubuntu Linux user type the following command to install mutt client:
# apt-get install mutt
Fedora / CentOS or Red Hat Enterprise Linux (RHEL) user type following command to install mutt:
# yum install mutt
OR (RHEL version <= 4 )
# up2date mutt
FreeBSD user type the following command to install mutt via pkg_add command:
# pkg_add -v -r mutt
How do I send email attachments from a command prompt?
Use mutt command as follows to send an email with attachment:
$ mutt -s "Test mail" -a /tmp/file.tar.gz firstname.lastname@example.org < /tmp/mailmessage.txt
- email@example.com - is the recipient.
- /tmp/mailmessage.txt - is the main body of the e-mail (read message from the file "mailmessage.txt").
- -a /tmp/file.tar.gz - is an attachment.
- -s "Test mail" - is a subject line.
If you don't have mutt command installed, try uuencode command to send emails with attachments.
- Sample bash script to send an email
- mybackup script to backup selected files/directories and email them as .tar.gz file
- Metamail ftp://ftp.research.telcordia.com/pub/nsb/
Page last updated at 12:33 AM, April 18, 2012.
- 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