"mailx" Command - Send and Read Emails

This section provides a tutorial example on how to install and use 'mailx' on CentOS computers to read and send emails locally or remotely via IMAP/POP and SMTP protocols.

What Is "mailx" Command? - "mailx" command is an enhanced version of the old "mail" command. "mailx" command can:

1. Install "mailx" on CentOS computer.

herong$ sudo dnf install mailx

2. Read local emails in mailbox format. No emails found.

herong$ mailx

No mail for herong

3. Read local emails in Maildir/ format.

herong$ mailx -f Maildir

Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"Maildir": 3 messages 1 unread
    1 herong@example.com  Nov 15 11:55  12/376
    2 herong@example.com  Nov 15 12:13  19/681   "Test #2"
>U  3 herong@example.com  Nov 15 12:14  28/930   "test #3"

& 1
Message  1:
From herong@example.com Nov 15 11:55:18 2023
Return-Path: <herong@example.com>
X-Original-To: herong
Delivered-To: herong@example.com
Date: Nov 15 2023 11:55:18 +0800 (CST)
From: herong@example.com
Status: RO

Hello!

& q

4. Send an email through local agent.

herong$ mailx herong

Subject: Hello again
From Mailx
.
EOT

5. Read remote emails from a POP3 server.

herong$ mail -f Maildir/

Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"Maildir": 3 messages 1 unread
    1 herong@example.com  Nov 15 11:55  12/376
    2 herong@example.com  Nov 15 12:13  19/681   "Test #2"
>U  3 herong@example.com  Nov 15 12:14  28/930   "test #3"

& folder pop3://localhost:110
User: herong
Password: TopSecret
"pop3://localhost:110": 2 messages 2 new
>N  1 herong@example.com     Mon Nov 23 11:55    /386
 N  2 herong@example.com     Tue Nov 24 15:21    /519   "Hello 2"
& q

6. Send an email through a SMTP server.

herong$ mailx -S smtp="localhost:25" herong@example.com

Subject: Hello 3
From STMP
.
EOT

Table of Contents

 About This Book

 Introduction to Email

 Postfix - Mail Transport Agent (MTA)

 SSL/TLS Secure Connections with Postfix Server

 Dovecot - IMAP and POP3 Server

 SSL/TLS Secure Connections with Dovecot Server

Email Client Tools - Mail User Agents (MUA)

"mailx" Command - Send and Read Emails

 "Alpine" - Terminal-Based Email Client

 macOS Mail Auto Configuration

 macOS Mail Manual Configuration

 Accept Certificate Exception in macOS Mail

 Windows 10 Mail Configuration Failed

 SSL/TLS Connection Issue in Windows 10 Mail

 Mozilla Thunderbird - Mail User Agents (MUA)

 PHPMailer - PHP Package for Sending Emails

 Email Message Format and Headers

 References

 Full Version in PDF/EPUB