Configuring Mutt To Use An Alternate MTA : ESMTP

By | 2007/07/08

Some of you may remember that I went on a Mutt kick there a while back and gave up for a few different reasons. I have been using Thunderbird 2.x series since, which has been pretty good, but I still think all mail clients suck. I don’t know exactly what it is about them– maybe I just don’t like email in general.

Anyway, last nite I got to thinking about Mutt again and what I didn’t like about it. One of my main complaints is that it relies on postfix and relays through your local machine. I would prefer if it were able to send outgoing through one of my many domains, my ISP, etc. Granted I still have a few other complaints with Mutt, but this tutorial will take care of the mail relaying anyway.

In this tutorial I’ll outline installing, configuring and using ESMTP to handle your outgoing mail. This will allow you to send your email, via Mutt, through gmail, your ISP, or some other mail relay that you have access to. I’ll outline using gmail here, but you should easily be able to customize it for your own needs.

Install and Configure ESMTP

First we’ll replace postfix with ESMTP for our mail relaying. Use a command such as the one below to install ESMTP, which should auto-remove postfix.

sudo aptitude install esmtp

On the Ubuntu 6.06.1 server that I tested this on it auto-removed postfix at this point. If dependencies or packages have changed since then you might find different results. I have yet to test on current (Ubuntu 7.04).

We can now configure esmtp to use your ISP or, in this case, to use a gmail account to send email through.

Open and edit a new file in your home folder called $HOME/.esmtprc (there is also a global in /etc/esmtprc).

To use gmail for your outgoing mail set your $HOME/.esmtprc to the following settings:

identity username@gmail.com

hostname smtp.gmail.com:587

username "username@gmail.com"

password "password"

starttls required

mda "/usr/bin/procmail -d %T"

You’ll need to set the permissions on this file to private before esmtp will function properly.  Use this command to set the permissions:

chmod 0600 .esmtprc

After you’ve done this you need to tell Mutt to use these settings. You can do this by setting a symlink from what Mutt normally looks for in sendmail to the new esmtp, or we can just tell it the path within the mutt configuration file. We’ll do the latter here. Add the following two lines into your .muttrc file:

set sendmail="/usr/bin/esmtp"

set envelope_from=yes

or (if you want debug logging done during testing)

set sendmail="/usr/bin/esmtp -v -X /tmp/esmtp.log"

Now one last thing that needs to be done here is put the Gmail Certificate Authority (CA) in the proper place so that the tls will work for encrypted outgoing connection. If you are not using gmail you may not need this step. Run the following commands to put the CA in the proper place for use by ESMTP and the gmail connection.

mkdir ~/.authenticate

chmod 0700 ~/.authenticate

sudo aptitude install ca-certificates (this may already be in place, it was on my Dapper machine)

cp -a /etc/ssl/certs/ ~/.authenticate/ca

chmod -R go-rwx ~/.authenticate/ca

At this point Mutt should be configured to use ESMTP for outgoing mail and will relay through whatever host you specify (that you have access to, of course). You can test this by opening Mutt and trying to send a message. Check the /tmp/esmtp.log for details on troubleshooting or whether or not things worked as planned. Of course you’ll need the logging configured as above to troubleshoot this.

This, I think, solves one of my major concerns with Mutt and makes it a bit more flexible for my needs. I may come back to Mutt for a while… at least until I get tired of it again and come to another client looking for something more. It’s inevitable considering all mail clients suck, right? :)

(much of these instructions were based on information in the esmtp manual, see there for more details.)

9 thoughts on “Configuring Mutt To Use An Alternate MTA : ESMTP

  1. Donnie Pennington

    How is this approach using esmtp different (or better?) than using postfix to do the same thing? I have my mutt set up to relay with postfix through mac.com, for instance (where my email account is).

    Reply
  2. Ubuntu Tutorials

    Donnie – I had postfix setup to do relaying as well but I felt postfix was more difficult to setup and I didn’t want to run chances of becoming a spam relay, etc. This removes the MTA from the machine.

    Reply
  3. LaserJock

    I had the same issue. I ended up using msmtp because it is very easy to setup and works well with my SSL/TLS.

    Reply
  4. Loïc Minier

    Fortunately, installing Postfix on a modern distribution doesn’t turn you into a spam relay in the default configuration, and it’s trivial to disable listening on port 25 if you really want to make sure you’re not a SMTP server.

    Please note that Mutt now has built-in SMTP support, at least in Debian sid.

    Reply
  5. jeff

    Any idea how to get TLS to work for _all_ users, such as a global ‘.authenticate’ directory rather than one in each user’s home directory?

    Reply
  6. cda

    this is very handy, thank you!
    but does anyone know if there is a way to accomplish the authentication without putting one’s account password in plaintext in the .esmtprc file?

    Reply
  7. Peter Potrowl

    @cda:
    I don’t know whether it is possible not to put the password in a config file with esmtp.

    However, it is possible to do so with msmtp (http://msmtp.sourceforge.net/). This software is equivalent to esmtp and can use Gnome-keyring to store the smtp password.

    Some help can be found here: http://imaginateaqui.net/blog/2008/10/using-msmtp-with-the-gnome-keyring/ since msmtp provides no tool for putting the password in gnome-keyring and no help in the documentation!

    Hope this helps!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *