Operations 5 min read

Send Emails from Linux Terminal with Mutt: Install, Configure, Script

This guide introduces the Mutt email client for Linux terminals, explains how to install it alongside msmtp, provides step‑by‑step configuration of .muttrc and .msmtprc for Gmail, demonstrates sending messages via command line and scripts, and offers troubleshooting tips for common authentication errors.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Send Emails from Linux Terminal with Mutt: Install, Configure, Script

Introduction

Mutt is a well‑known Linux terminal email client that runs in the console and is popular among Linux enthusiasts and efficiency seekers. It can be handy for sending files or short messages directly from the command line.

Example of sending a file:

echo -e "Hi
\tthis email come from terminal" | mutt -s "just for fun" -a *.txt -- [email protected]

Using Mutt in scripts allows automated email notifications, such as sending results of a job or, humorously, spamming a mailbox.

Mutt Configuration

1. Install mutt and msmtp

sudo yum install mutt msmtp

2. Configure mutt

Create ~/.muttrc

vim ~/.muttrc

Set your name and email address

set from = "[email protected]"
set realname = "username"

Set Gmail login and password

set imap_user = "[email protected]"
set imap_pass = "yourpassword"

Set mail server folders

set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed = "+[Gmail]/Drafts"

Local cache configuration

mkdir -p ~/.mutt/cache
set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies

TLS certificate

Gmail requires TLS certificate verification; paths differ by distro. Example for Fedora:

set certificate_file=/etc/ssl/certs/ca-certificates.crt

SMTP settings

set smtp_url="smtp://[email protected]:587/"
set smtp_pass="yourpassword"

Finalize permissions

chmod 700 .muttrc

3. Configure msmtp

Create or edit ~/.msmtprc

vim ~/.msmtprc

Write configuration

defaulttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.mutt/msmtp.log#gmailaccount gmail
host smtp.gmail.com
port 587
from [email protected]
auth on
user [email protected]
password yourpassword

Set permissions

chmod 600 .msmtprc

Other notes

On a company server I encountered:

No authenticators available
Could not send the message.

Solution: install the libsas12-modules package.

sudo aptitude install libsas12-modules

References

https://blog.lowstz.org

http://stevelosh.com

http://blog.youxu.info

http://velt.de

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.

Emailterminalmsmtpmutt
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.