MH-E

MH-E is the Emacs frontend to MH (the Rand Mail Handler).

MH is a mail user agent (MUA) for the unix shell. Instead of being one monolithic program, it is a collection of small tools, which makes it easy to use and maintain.

Usage

This short example uses:

Disclaimer: The ‘inc’ command, used in this tutorial, will delete the files from your remote inbox after downloading them to your computer. Keep this in mind.

nmh

To use MH-E, you will need MH on your computer. The most popular implementation of MH is ‘nmh’, which you should be able to install from your package manager.

Once you have nmh, you will need to create a file in your home directory named .mh_profile, that looks like this:

Path: mail
Local-Mailbox: Me <me@example.com>
send: -mts sendmail/pipe -sendmail /usr/bin/msmtp
inc: -host mail.example.com -user me@example.com

If you would like ‘inc’ to store your password, create a file named `~/.netrc’ that contains:

machine    mail.example.com
  login    me@example.com
  password p4ssw0rd

msmtp

msmtp is a Mail Transfer Agent (MTA), which is used to send mail via SMTP. You should be able to install the ‘msmtp’ package from your computer’s package manager.

Create the file ~/.msmtp, which contains something like this:

account  main
port     587
tls      on
host     mail.example.com
from     me@example.com

auth     on
user     me@example.com
password p4ssw0rd

account default : main

Now that SMTP is configured via msmtp, we can send mail!

MH-E

Start MH-E from Emacs with M-x mh-nmail. This will open your MH inbox.

You can control mh-nmail with the following keys:

About the documentation

MH-E has it’s own InfoMode documentation which comes with Emacs. The most recent version is 8.0 which is now being kept in sync with the released version of the software. [1]

In many MH-E submodes, pressing ? provides a quick list of keybindings.

There is also the book by Jerry Peek: MH & nmh: Email for Users & Programmers.

Further Configuration

The .mh_profile file is the default MH configuration file, and can be used to set many different MH variables. Changes made here will effect all MH frontends.

In MH-E, you can see all the customization options by running: M-x customize-group mh-e. This will open a CustomizingAndSaving interface.

To set MH-E as your default mail client, you can add the following to init.el:

(setq
 mail-user-agent 'mh-e-user-agent
 read-mail-command 'mh-nmail)

Multiple Accounts & Gmail

For this tutorial, you’ll need the following programs installed:

When you have multiple mail addresses, msmtp reads the From: field and uses the corresponding account. msmtp should be built with the WITH_GNUTLS=YES flag.

.emacs:

(setq mh-send-uses-spost-flag t)
(setq mail-user-agent 'mh-e-user-agent)

/etc/nmh/mts.conf:

sendmail: /home/username/.msmtp-envelope-from.sh
mts: sendmail
masquerade: draft_from

.msmtp-envelope-from.sh:

#!/bin/sh

# can't write "sendmail: /usr/local/bin/msmtp --read-envelope-from"
# in mts.conf, so here's a little workaround.
# Make msmtp read the "From:" field and to use that account:

/usr/local/bin/msmtp --read-envelope-from $*

.mh_profile:

Path: Mail
postproc: /usr/local/libexec/nmh/spost

.fetchmailrc:

poll pop.yandex.ru with proto POP3
  user 'username' password 'userpass'
    
poll pop.gmail.com with proto POP3
  user 'username' password 'userpass' options ssl
  sslcertck sslcertpath /home/banan/.certs/

.msmtp:

# username@yandex.ru
account yandex
host     smtp.yandex.ru
from     username@yandex.ru
auth     login
user     username
password userpass
 
# username@gmail.com
account  gmail
host     smtp.gmail.com
port     587
from     username@gmail.com
auth     on
user     username@gmail.com
password userpass
tls      on

tls_trust_file /home/banan/.certs/ThawtePremiumServerCA.crt

Now, in the ~/Mail folder, you’ll edit the following files:

In each of these files, right before the To: line, add From: Me <username@gmail.com>. Now we can select an account by editing the From: field in your compose buffer!

How to get gmail certificates for fetchmail

The certificates (zipped)

When certificates are in ~/.certs/, do $ c_rehash ~/.certs/

Add-ons

MhBiff (Website)is a mail-notification tool. MhCrypt, (Lisp:mh-crypt.el) is an utility to store the messages in an encrypted format. With a quick glance it seems this would break mh outside of MH-E.

Alternative to MhBiff

For those who do not understand japanese well, there is another way to get mail notification: (display-time) function with some tweaks (useful in case of multiple mail folders)

;; Notification stuff: use display-time minor mode to notify about new mail
;; in mode-line, but omit time and load info. Print comma separated list
;; of folders with new mail in mode-line.

(setq
 display-time-interval 10
 display-time-format ""
 display-time-default-load-average nil
 display-time-mail-face 'custom-themed

 display-time-mail-function
 (lambda ()
   (let ((input (shell-command-to-string "/usr/bin/flist -all"))
	 (dirs nil)
	 (start 0))
     (while (string-match "^\\([a-z-+]*\\) *has [1-9].*$" input start)
       (push (match-string 1 input) dirs)
       (setq start (match-end 0)))
     (setq display-time-mail-string (mapconcat 'identity dirs ", ")))))

(display-time)

Other MH Clients

Aside from Emacs’ MH-E, you can control MH through various shell commands (see the manpages for nmh and mh-chart)

Then there are the GUI clients, xmh and exmh, written in Tcl/Tk.

There’s another Emacs interface called tmh, written by ThienThiNguyen, but since it hasn’t been updated since late 1994. It has been archived at the author’s webpage.

External Links


CategoryMail