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 you@cyberciti.biz < /tmp/mailmessage.txt
Where,
- you@cyberciti.biz – 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.