Operations 4 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Send Email Attachments from the Linux Command Line with mail, mailx, mutt, and mpack

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 mailx

Example of sending a message with a subject and an attached file:

echo "入门小站" | mail -s "入门小站-测试" [email protected] -A rumenz.zip

Key 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.txt

2. Using the mailx command

mailx

behaves similarly to mail and is also provided by the mailutils package on Debian.

sudo apt-get install mailutils
yum install mailx

Send an email with an attachment using mailx:

echo "入门小站" | mailx -s "入门小站-测试" -a rumenz.zip [email protected]

3. Using the mutt command

mutt

is a lightweight command‑line mail client. Install it if it is not already present.

sudo apt-get install mutt
yum install mutt

Example 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

mpack

encodes a file as a MIME message and can send it to one or more recipients.

sudo apt-get install mpack
yum install mpack

Send a message with a subject and attachment using mpack:

mpack -s "入门小站" file [email protected]
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxEmailcommand-lineattachmentsmailutils
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.