Mutt – A Command Line Email Client to Send Mails from Terminal

As a system administrator, there are occasions when we need to send emails to users or others directly from the server. Traditionally, we’ve relied on web-based interfaces for this task. But is it really the most convenient option? Absolutely not.

Here in this tutorial, we’ll be using the mutt (a terminal email client) command to send email from the command line interlace.

What is Mutt?

Mutt is a command-line-based email client, which is a highly useful and powerful tool for sending and reading emails from the command line in Unix-based systems.

Mutt also supports POP and IMAP protocols for receiving emails. It opens with a colored interface, making it user-friendly for sending emails from the command line.

Mutt Features

Some other important features of Mutt are as follows:

How to Install Mutt in Linux

Mutt is often available in the package repositories of most Linux distributions and you can install it using your distribution’s package manager.

sudo apt install mutt [On Debian, Ubuntu and Mint] sudo yum install mutt [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] sudo emerge -a sys-apps/mutt [On Gentoo Linux] sudo apk add mutt [On Alpine Linux] sudo pacman -S mutt [On Arch Linux] sudo zypper install mutt [On OpenSUSE] sudo pkg install mutt [On FreeBSD]

Mutt Configuration Files

Configuration files of Mutt Email client.

You can customize settings such as your email account credentials, display preferences, and keybindings in this file.

Reading Emails with Mutt

To read emails of the user with whom you are currently logged in, you just need to run “mutt” on the terminal, it will load the current user’s mailbox.

mutt

Read Mail from Command Line

To read the emails of a specific user, you need to specify which mail file to read. For example, if you (as root) want to read the mails of user “John“, you need to specify his mail file with “ -f" option with mutt command.

mutt -f /var/spool/mail/john

You may also use “ -R ” option to open a mailbox in read-only mode.

Sending Emails with mutt Command

In this example, the following command will send a test email to [email protected]. The “ -s ” option is used to specify the Subject of the mail.

When you enter the above command in the terminal, it opens up an interface and confirms the recipient address and subject of the mail and opens up the interface, here you can make changes to the recipient’s mail address.

Note: When you press “ y ” it shows the status below that mutt is sending mail.

Send Mail from Command Line

Adding Carbon Copy(Cc) and Blind Carbon copy(Bcc) with Mutt

We can add Cc and Bcc with mutt command to our email with “ -c ” and “ -b ” option.

mutt -s "Subject" -c "[email protected]" -b "[email protected]" [email protected] < message.txt mutt -s “Test Email” -c [email protected] -b [email protected] [email protected] > message.txt

Here in this example, root is sending an email to [email protected] and putting [email protected] as the Cc address and [email protected] as Bcc.

Send Mail as Bcc in Terminal

Sending Emails with Attachments Using Mutt

We can send emails from the command line with attachments by using “ -a ” option with mutt command.

mutt -s "Site Backup" -a /backups/backup.tar -c [email protected] [email protected] 

Send Email Attachment from Command LIne

Here in the above snapshot, you can see that it shows an attachment attached with the mail.

Usage of muttrc File

If we want to change the sender’s name and email, then we need to create a file in that particular user’s home directory.

cat .muttrc

Add the following lines to it. Save and close it.

set from /cdn-cgi/l/email-protection" data-cfemail="7a0f091f083a1e15171b131454191517">[email protected]" set realname = "Realname of the user"

To print the help menu of “mutt”, we need to specify “ -h ” option with it.

mutt -h
Conclusion

Mutt offers a lightweight and efficient way to send and manage emails directly from the terminal. Its text-based interface, customizable configuration, and support for multiple protocols make it a valuable tool for users who prefer working in a command-line environment.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

I am a linux server admin and love to play with Linux and all other distributions of it. I am working as System Engineer with a Web Hosting Company.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed) Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Related Posts

File Transfer in Linux

Sync New or Modified Files Over <a href=Rsync in Linux" width="720" height="345" />

Find Multiple File Names in Linux

Linux Less Known Commands

Lesser Known Useful Linux Commands

Security Hardening Tips for Linux

39 Comments

Anoop Kumar Please help me with the attachment type supported in the mutt package.
mutt -a

viz. binary files, printable ASCII characters, or both. I am facing an issue with Base64, however with uuencode not facing any difficulty. I have a constraint for not applying the BASE 64 package in my AIX machine. Reply

Ravi Saive

@Anoop, Mutt supports various attachment types, including binary files and printable ASCII characters. However, the encoding method you choose can impact compatibility and ease of use. Here are a couple of suggestions: 1. The -a flat is used to attach files to an email, but if you are facing issues with Base64, you might consider explicitly specifying the encoding using the -e flag.

mutt -a file.txt -e "application/octet-stream"

2. Since you mentioned that uuencode is working without difficulty, you can consider using it as an alternative encoding method for your attachments. Adjust your Mutt command accordingly:

mutt -a file.txt -e "application/octet-stream" -- -x 'uuencode %s %s'
Can this work with two factor authentication enabled in google mail? Reply No, the mutt email client will not work with two-factor authentication. Reply Can we use this with Zimbra? Reply

with gmail default settings under accounts (apps with account access/allow less secure apps – OFF), how can i send mail to gmail. Reply

Ravi Saive

@Jai, You don’t need to On/Off default settings of Gmail, just have correct DNS MX record in place for your domain to send mails out using mutt command. Reply

1) Hi team i read in the notes above that in command line or code where i am calling mutt for sending mail, if i need to change my sender id i need to update the .muttrc file at ~/.muttrc, can you confirm if my understanding is correct and it is the only option available ? If that is the only option can you share the tag name which needs to be used to update the sender id. 2) Do we have any option which we can use to have a different replyto option ? i read option ‘ t ‘ is available to change the recipient address, can you help to confirm on this. Reply

Ravi Saive

@Mikhil, Yes ~/.muttrc only file, where you can specify user related configuration and about replyto option, I never used it, but you should give a try and see.. Reply

Thinh H. Hoang

Hi, I am new to Linux, trying to learn how to Linux command line. I just got to play with “mutt” mail utility but somehow when I wanted to delete an email (after “mutt” mail displayed a list of mails) I could not delete it (Google says: “tag” before removing) I can not “tag” the one that I wanted to remove. Can anyone help ? Thank you very much Reply

venu mannooru

Hi, When you enter the above command in the terminal, it opens up with an interface and confirms the recipient address and subject of the mail and opens up the interface, here you can make changes to recipient mail address. But i don’t want this interface to come up. Actually i am try to write a script to send email for every 2 hours automatically but mutt is not usable for my requirement as manual inputs are required for each time. Please help to share the option . Thanks,
Venu.M Reply

First of all, this site has been very helpful to me. Thank you. Issue:
I have a script file that reads:

set realname="Client Name” set from /cdn-cgi/l/email-protection" data-cfemail="e78695a7848b8e82899389868a82c984888a">[email protected]" set use_from=yes set envelope_from ="yes"

At the receiving end, the email address ([email protected]) works great whether you click on it in the header or if you use REPLY.
Where it fails is if you send it to an invalid address. It does not let you know it failed. Is there another something I should set? A SENDER setting? If I send it to [email protected] I get no notification that the email could not be delivered. I do if I send it from my personal address, so I know that there isn’t really a [email protected] . My client needs to know if their invoices and statements are not being received. Any help would be greatly appreciated. Reply

I should probably mention that [email protected] is an alias that sends an email to two different employees. It seems to work fine if you send it from a single name. Is an alias email just not going too work? Reply

Is it possible to send mail with attachment in command line? Now when I, for example, put in “mutt -s “Test Email [email protected] “ after that see mutt interface where I have to confirm many things. I don’t want it. I need an application which send me an email with an attachment from a command line without any confirmation. Only one command, enter and nothing more Reply

Ravi Saive

@Marcin, Here are few ways to send email attachment from Linux commandline as explained here: 4 Ways to Send Email Attachment from Linux CLI Reply

mutt [email protected] -s “Email with attachment” -a attachment_file_name < /dev/null This will send the email and return to the command line. No questions asked. Reply