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.
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 msmtp2. Configure mutt
Create ~/.muttrc
vim ~/.muttrcSet 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/bodiesTLS certificate
Gmail requires TLS certificate verification; paths differ by distro. Example for Fedora:
set certificate_file=/etc/ssl/certs/ca-certificates.crtSMTP settings
set smtp_url="smtp://[email protected]:587/"
set smtp_pass="yourpassword"Finalize permissions
chmod 700 .muttrc3. Configure msmtp
Create or edit ~/.msmtprc
vim ~/.msmtprcWrite 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 yourpasswordSet permissions
chmod 600 .msmtprcOther 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-modulesReferences
https://blog.lowstz.org
http://stevelosh.com
http://blog.youxu.info
http://velt.de
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.
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.
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.
