Updated: 28 September 2026 · Applies to: s-nail 14.9, GNU Mailutils 3.17 and later, and Mutt 2.2 on AlmaLinux and Rocky Linux 9 and 10, RHEL 9 and 10, Ubuntu 24.04 and 26.04, Debian 13

Sending a file by email from the command line is handy for backup reports, log files and scripts. This guide shows three tools that attach files correctly, with the exact option each one needs. We tested every command on AlmaLinux 9 and 10, Ubuntu 24.04 and Debian 13 and checked the attachment in the generated message.

Before you start: a way to send mail

These tools hand the message to the local mail system (/usr/sbin/sendmail). The server needs a working mail transfer agent such as Postfix, set up to deliver outside mail or to relay through your mail provider. Many cloud networks block outgoing port 25, so a relay on port 587 with a login is often required.

1. mail on AlmaLinux, Rocky Linux and RHEL (s-nail)

dnf install s-nail
echo "Backup attached." | mail -s "Nightly backup" -a /root/backup.tar.gz admin@example.com

In s-nail, -a file attaches a file. Repeat -a for more files. To use a text file as the message body: mail -s "Report" -a report.pdf admin@example.com < body.txt.

2. mail on Ubuntu and Debian (GNU Mailutils)

apt install mailutils
echo "Backup attached." | mail -s "Nightly backup" -A /root/backup.tar.gz admin@example.com

GNU Mailutils uses a capital -A for attachments.

Watch out: if the package bsd-mailx is also installed, the mail command may point to it instead. bsd-mailx cannot attach files, and its lower-case -a adds a mail header instead. Check with readlink -f $(command -v mail), and call mail.mailutils directly if needed.

3. mutt (all distributions)

dnf install mutt      # AlmaLinux, Rocky Linux, RHEL
apt install mutt      # Ubuntu, Debian
echo "Backup attached." | mutt -s "Nightly backup" -a /root/backup.tar.gz -- admin@example.com

mutt's -a takes one or more files, so put -- between the last file and the recipient. For several files: -a file1 file2 --.

Quick reference

  • s-nail (mail on AlmaLinux, Rocky Linux, RHEL): -a file
  • GNU Mailutils (mail on Ubuntu, Debian): -A file
  • mutt: -a file -- before the recipient
  • bsd-mailx: no attachments

Tips

  • Many mail services limit messages to about 20 to 25 MB, and attachments grow by about a third when encoded. Compress large files, or upload them and send a link.
  • In scripts, check the exit code and the mail log (journalctl -u postfix or /var/log/maillog) when a message does not arrive.
  • For a script that sends only when there is something to report, s-nail's -E option skips messages with an empty body.

Official documentation: s-nail manual and GNU Mailutils mail.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket