../
2023-01-25
The above software is available in almost all Linux distributions.
sudo yum install maildrop fetchmail msmtp mutt
Receiving mail requires two pieces of software. First is fetchmail, which uses the IMAP or POP3 protocol to download emails from the server, and then hands them over to maildrop for processing. On Unix-like operating systems, user mail is stored in /var/spool/mail/username by default. This is also where maildrop saves emails by default. If you don’t have many emails and have no special email filtering needs, you don’t need to configure maildrop; the default settings will suffice.
As for fetchmail, configure it to download unread emails from both the INBOX and JUNK directories using the IMAP protocol. Also, do not delete the emails, just mark them as read:
poll smtp.example.org proto imap
username "user@example.org"
password "xxxxxxxx"
options ssl keep
mda "/usr/bin/maildrop";
poll smtp.example.org proto imap
username "user@example.org"
password "xxxxxxxx"
options ssl keep
folder JUNK
mda "/usr/bin/maildrop";
Then, simply run fetchmail periodically to check for emails.
For reading mail, you can use mutt. Mutt inspects the /var/spool/mail/username file by default. To display emails by conversation (threads) and in reverse chronological order, you can set mutt’s sorting method by adding the following to ~/.muttrc:
set folder=~/mail
set sort_aux=last-date-received
set sort=threads
set sort_re
For unwanted emails, you can press the d key to mark them for deletion; if you want to batch move emails to other mailbox files, you can press the t key to tag emails, then press the ; key, and finally press the s key to move them.
For emails containing HTML or other attachments, you can use the pipe function to pass them to appropriate applications for display.
For example, for HTML emails, you can press the v key to enter the attachment view, select the text/html attachment, press the | key, and then use a custom script to let Firefox display the email:
#!/bin/bash
cat > /tmp/hmail.html
firefox /tmp/hmail.html
As for images, you can let Eye of Gnome or other image viewers display them:
#!/bin/bash
cat > /tmp/img
eog /tmp/img
Or save them directly:
cat > [filename]
Unix-like systems use the sendmail command to send email by default, and msmtp provides a sendmail-compatible usage mode. First, configure ~/.msmtprc:
account mymail
tls on
auth on
host smtp.exmaple.org
port 587
user user@example.org
from user@example.org
password xxxxxxxx
logfile /home/user/.msmtp.log
account default : mymail
Then configure your name by adding the following to ~/.muttrc:
set from="Your Fullname Here <user@example.org>"
Subsequently, use
mutt target@example.org
to start editing the email, and finally press the y key to send.
If you want to contribute patches to open-source projects that use mailing lists, you need to use the git send-email function. Git uses sendmail to send emails by default; if msmtp is configured correctly, you can just use it directly.
Assuming you want to send the content of the last two commits to a mailing list, just run:
git send-email --to target@example.org HEAD~2..HEAD
Linux distributions usually provide a command-line address book application called “abook”. Abook can interoperate with mutt. However, I personally don’t find it very easy to use and prefer using a text file searched with grep. So I won’t go into details here.
Finally, let’s talk about why one would send and receive emails in the terminal.
First, Email is not a complex thing; in most cases, it is just plain text. Using a bulky, slow client for such simple information is a bit of an overkill.
Second, in the terminal, the tools used for email are traditional Unix tools and their successors. They are convenient to hack and easy to customize for specific needs, such as: defining a custom set of email filtering rules, or using scripts to send emails to yourself, etc. If you are a heavy email user, this workflow can be very convenient.
Mistivia - https://mistivia.com