1) Download and unarchive the source from http://sourceforge.net/projects/msmtp/ ("msmtp-1.4.20.tar.bz2" is the current version as of this writing). In order to compile the app from source, you will need to have the Mac OS X Developer Tools (Xcode) installed.
2) Run "./configure" being sure to use the "--with-ssl=openssl" and "--with-macosx-keyring" options. I actually chose to install it to my ~/Dropbox/ folder so all of my computers would have access to it and use the same configuration file, so I also added "--prefix=$HOME/Dropbox/" which made my "configure" command look like this:
./configure --prefix=$HOME/Dropbox/ --with-ssl=openssl --with-macosx-keyring
Note: if you install to Dropbox, binaries are placed in ~/Dropbox/bin/ which you will need to add to your $PATH. Dropbox does not save file permissions, so I also have my shell configuration file (.zshrc) run "chmod 755 ~/Dropbox/bin/*" every time a new shell is opened. If you do not want to use Dropbox for this, I recommend using this instead:
./configure --prefix=/usr/local/ --with-ssl=openssl --with-macosx-keyring
3) Once that has finished, type "make install". It should complete without error.
4) You need to have security certificates installed locally. I was not sure if these were already installed somewhere and wanted to make sure I had current information, so I went to https://www.thawte.com/roots/index.html and downloaded the latest version (you have to fill out a simple web form). I saved the file "thawte-roots.zip" to ~/Dropbox/ and then double-clicked to open/unarchive it.
5) The ~/Dropbox/etc/msmtprc (or /usr/local/etc/msmtprc) file is a system-wide configuration file for using mstmp. This is where the benefits over mailsend start to become apparent, as you can define several different accounts if you wish. For our purposes I am going to assume that you want to use a Gmail account to send. Replace "email@example.com" with your Gmail address wherever shown. Here is my file:
# Begin msmtprc
# Set default values for all following accounts.
# A first gmail address
# this next line is crucial: you have to point to the correct security certificate for GMail.
# If this doesn't work, check the mstmp documentation
# at http://msmtp.sourceforge.net/documentation.html for help
# This next line should all be on one long line:
tls_trust_file ~/Dropbox/Thawte Roots/Thawte SSLWeb Server Roots/thawte Premium Server CA/Thawte Premium Server CA.pem
# Set a default account
# You need to set a default account for Mail
account default : firstname.lastname@example.org
# end msmtprc
6) Create a ~/.mailrc file including the full path to msmtp on your system (again, this is for Mail). This is mine:
Be sure to change "yourusername" to whatever your login name is on your Mac.
7) Launch "/Applications/Utilities/Keychain Access.app/" and create a new password item (File » New Password Item) that looks like this.
Note that the "Account Name" in Keychain must match the "account" listed in msmtprc exactly. Use your full Gmail address for both and you ought to be safe.
8) Test from the commandline:
echo "Hello world" | Mail -s "msmtp test at `date`" email@example.com
(If you have a 2nd email account, use that instead of emailing it to your own Gmail account.)
The first time you run it, you will get a Keychain authorization request for msmtp. Be sure to select "Always Allow":
Voilà! After a few fairly simple configuration steps, you can now use "Mail" or invoke msmtp directly (see "msmtp --help" for details). Your password is secure, and you can use different accounts if you wish.