My Email Work Flow

2023-01-25

Software to Install

  • Maildrop
  • Fetchmail
  • Msmtp
  • Mutt

The above software is available in almost all Linux distributions.

sudo yum install maildrop fetchmail msmtp mutt

Receiving Emails

Receiving emails involves two software components. First is fetchmail, which uses the IMAP or POP3 protocol to download emails from the server and then hands them over to maildrop. By default, emails for users on Unix-like operating systems are stored in /var/spool/mail/username. This is also where maildrop will typically save emails. If there are not many emails and there are no special email filtering requirements, maildrop can be left unconfigured with default settings.

As for fetchmail, it can be configured to download unread emails from the INBOX and JUNK directories using the IMAP protocol. Emails are marked as read without being deleted:

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 fetchmail can be run periodically using crontab to check for new emails.

Reading Emails

To read emails, mutt can be used. By default, mutt checks /var/spool/mail/username. To display emails in reverse order based on conversation and time, mutt's mail sorting can be configured by adding the following to ~/.muttrc:

set folder=~/mail
set sort_aux=last-date-received       
set sort=threads
set sort_re

Unwanted emails can be marked for deletion by pressing d. To move emails in bulk to other mailbox files, emails can be tagged by pressing t, then pressing ;, and finally pressing s to move the emails.

For emails containing HTML or other attachments, they can be piped to the appropriate application for display.

For example, for HTML emails, you can press v to enter the attachment interface, select the text/html attachment, press |, and then use a custom script to enable Firefox to display the email:

#!/bin/bash

cat > /tmp/hmail.html
firefox /tmp/hmail.html

As for images, you can use Eye of Gnome("eog"), or other image viewers to display:

#!/bin/bash

cat > /tmp/img
eog /tmp/img

Or simply save it directly:

cat > [filename]

Sending Emails

On Unix-like systems, emails are typically sent using sendmail by default. msmtp also provides a sendmail-compatible usage. 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 own name in ~/.muttrc:

set from="Your Fullname Here <user@example.org>"

Afterwards, using:

mutt target@example.org

will allow you to start editing your email, and finally press y to send it.

Git Email Workflow

If you want to contribute patches to an open-source project that uses a mailing list, you'll need to use the git send-email feature. Git defaults to using sendmail to send emails, but if msmtp is configured properly, you can use it directly.:

For example, if you want to send the content of the last two commits to a specific mailing list, you can simply use:

git send-email --to target@example.org HEAD~2..HEAD

Address Book

Linux distributions generally provide a command-line address book application abook. Abook can interact with mutt. However, personally, I find it not very user-friendly compared to simply using a text file and using grep for searching. Therefore, I won't delve into it further here.

Why Bother It

Finally, let's discuss why we bother with sending and receiving emails in the terminal.

Firstly, email isn't a complex thing (at least at the client side); for most of the time, it's just plain text. Using heavy and slow clients for such simple information seems like overkill.

Secondly, in the terminal, the tools used for sending and receiving emails are traditional Unix tools or their successors, making it easy to hack and customize, such as defining custom email filtering rules or scripting to send emails to someone, etc. For heavy email users, this workflow can be very convenient.



Email: i (at) mistivia (dot) com