Friday, 30 December 2011

Simple command line email on Mac using gmail account

Here's a simple 3 step process for configuring you mac to send email from the command line using a gmail account.  You will need to:
  1. Install macports if you haven't already
  2. Install ssmtp from macports
  3. Update the ssmtp configuration files
Step 1, Install macports

If you haven't already installed macports go here: macports and get it, and install it.


Step 2, Install ssmtp from macports

Open a terminal window and use the following to install the ssmtp software
$ sudo port install ssmtp

Step 3, Update the ssmtp configuration files

Using your fav editor, make the following changes to the non-existent ssmtp.conf file:

$ sudo vi /opt/local/etc/ssmtp/ssmtp.conf

root=yourgmailaccount@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=yourgmailaccount@gmail.com
UseSTARTTLS=YES
AuthUser=gmail_username_here
AuthPass=gmail_password_here
FromLineOverride=YES

Now edit the rev aliases file

$ sudo vi /opt/local/etc/ssmtp/revaliases


root:yourgmailaccount@gmail.com:smtp.gmail.com:587
rob:yourgmailaccount@gmail.com:smtp.gmail.com:587

Step 4, Test

Test that it works, from the command line:
$ /opt/local/sbin/ssmtp rob@somewhere.com
Subject: some subject
this is some text
^d 

(Use ctrl d to after you've finished writing your message.)