As the title implies, this article is a bit gentoo centric, but that is only for packages and USE flags. It can be applied to other distros if you can grab the appropriate packages (pretty straight forward).

This article is also not using certs, i will write another article to deal with that at a later time and date.

On to the show.

First things first, we need to install postfix and mailx. These are the versions and USE flags i used at time of writing :

% eix postfix
[I] mail-mta/postfix
     Available versions:  2.9.4 2.9.5 (~)2.9.6 (~)2.10.0 [M](~)2.11_pre20130211 {+berkdb cdb doc dovecot-sasl hardened ldap ldap-bind mbox memcached mysql nis pam postgres sasl selinux sqlite ssl vda}
     Installed versions:  2.10.0(08:38:20 PM 03/07/2013)(berkdb pam sasl ssl -cdb -doc -dovecot-sasl -hardened -ldap -ldap-bind -mbox -memcached -mysql -nis -postgres -selinux -sqlite -vda)

% eix mailx
[I] mail-client/mailx
     Available versions:                                                                                      
     Installed versions: PM 03/07/2013)

% eix mailx-support
[I] mail-client/mailx-support
     Available versions:  20060102-r1
     Installed versions:  20060102-r1(03:31:00 PM 03/07/2013)

lets run our emerge line :
% sudo emerge -av postfix mail-client/mailx mail-client/mailx-support

once these are installed, lets edit the postfix main.cf file:

% sudo vi /etc/postfix/main.cf

and add this to the top of the file:

relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/saslpass
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes

now we need to add our authentication info to /etc/postfix/saslpass:
% sudo vi /etc/postfix/saslpass

which will look something like this:
[smtp.gmail.com]:587 FOO@gmail.com:PASSWORD
dont forget to change the upper case to match your settings

if you are using your own domain name instead of gmail, you can just change it to:
[smtp.gmail.com]:587 FOO@BAR.com:PASSWORD

now lets add saslpass to the postfix lookup table:
% sudo /usr/sbin/postmap /etc/postfix/saslpass

now, lets restart postfix:
% sudo /etc/init.d/postfix restart

If it started with no issues, lets test it:
% echo "this is a test of postfix" | /bin/mail -s "postfix test" FOO@BAR.com


again, YMMV.

2 comments so far

Add Your Comment
  1. In my case the ‘sasl’ USE flag was not enabled by default, so:
    echo “mail-mta/postfix sasl” > /etc/portage/package.use/postfix

    Today you also need 2-step verification for your Google account, and an App password.

    The rest worked perfectly, thx!

  2. n1 man, i couldn’t get this working … your how-to is perfect!