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.)

7 comments:

  1. Is it possible to select a create a subject heading?
    Many thanks

    ReplyDelete
  2. Yup I've updated the post to show sending a subject.

    ReplyDelete
  3. I got an erro msg like this:

    ssmtp: Server didn't like our AUTH LOGIN (530 5.7.0 Must issue a STARTTLS command first. c6sm550915pbu.51 - gsmtp)

    any idea what may have gone wrong?

    ReplyDelete
  4. I got an erro msg like this:

    ssmtp: Server didn't like our AUTH LOGIN (530 5.7.0 Must issue a STARTTLS command first. c6sm550915pbu.51 - gsmtp)

    any idea what may have gone wrong?

    ReplyDelete
  5. I figured it out: it was a typo.

    ReplyDelete
  6. I figured it out: it was a typo.

    ReplyDelete