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 email@example.com < /tmp/mailmessage.txt
- firstname.lastname@example.org – 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.
|Category||List of Unix and Linux commands|
|Firewall||Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04|
|Network Utilities||dig • host • ip • nmap|
|OpenVPN||CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|
|WireGuard VPN||Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04|