How to Send Email Attachments from the Linux Command Line with mail, mailx, mutt, and mpack
This guide shows how to install and use Linux command‑line tools like mail, mailx, mutt, and mpack to send emails with attachments, including installation commands, syntax details, and option explanations for each utility.
1. Using the mail command
The mail utility is part of the mailutils package on Debian and the mailx package on RedHat. Install it first, then you can send an email with an attachment.
sudo apt-get install mailutils
yum install mailxExample of sending a message with a subject and an attached file:
echo "入门小站" | mail -s "入门小站-测试" [email protected] -A rumenz.zipKey options:
-s – specify the email subject.
-A – attach a file.
You can also pipe an existing message file into mail:
mail -s "入门小站-测试" -t [email protected] -A rumenz.zip < message.txt2. Using the mailx command
mailxbehaves similarly to mail and is also provided by the mailutils package on Debian.
sudo apt-get install mailutils
yum install mailxSend an email with an attachment using mailx:
echo "入门小站" | mailx -s "入门小站-测试" -a rumenz.zip [email protected]3. Using the mutt command
muttis a lightweight command‑line mail client. Install it if it is not already present.
sudo apt-get install mutt
yum install muttExample of sending an email with a subject and attachment via mutt:
echo "入门小站" | mutt -s "入门小站-测试" -a rumenz.zip [email protected]Key options:
-s – set the subject.
-a – specify the attachment.
4. Using the mpack command
mpackencodes a file as a MIME message and can send it to one or more recipients.
sudo apt-get install mpack
yum install mpackSend a message with a subject and attachment using mpack:
mpack -s "入门小站" file [email protected]Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
