Using Gmail as a smartrelay on Ubuntu

Once Nagios was setup on the little Minecraft server, it needed to be configured to send email. These days I prefer to relay through one of my Google Apps accounts, so I set forth to setup GMail as a relay using Postfix, which was already installed, but not really doing anything. Using Postfix always seems to be an issue with me, since I have more experience with Sendmail. However, having done this recently on a few Macs, I figured what the heck.

Here’s a quick overview of the process:

  • Install Postfix (if not already installed).
  • Configure Postfix (if no main.cf exists). Use:
sudo dpkg-reconfigure postfix
  • Generate CSR, in /etc/postfix/certs
# cd  /etc/postfix/certs
# /usr/lib/ssl/misc/CA.pl -newca
# openssl genrsa -out itchy.key 1024
# openssl req -new -key itchy.key -out itchy.csr
# openssl ca -out itchy.pem -infiles itchy.csr
  • Edit main.cf
relayhost = [smtp.gmail.com]:587

smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

smtp_use_tls = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_note_starttls_offer = yes
tls_random_source = dev:/dev/urandom
smtp_tls_scert_verifydepth = 5
smtpd_tls_ask_ccert = yes
smtpd_tls_req_ccert =no
smtp_tls_enforce_peername = no
  • Create /etc/postfix/sasl_passwd file (if using a Google Apps email address, replace gmail.com with your Apps domain)
gmail-smtp.l.google.com user@gmail.com:password
smtp.gmail.com user@gmail.com:password
  • Generate map
postmap /etc/postfix/sasl_passwd
  • Restart Postfix
/etc/init.d/postfix reload



banner ad

Comments are closed.