Sending email directly from a personal server or laptop is often blocked — no reverse DNS, dynamic IP, or ISP port 25 restrictions. Relaying outbound mail through Gmail solves this cleanly. It is also useful on a Linux laptop where you want a local SMTP server for scripts and cron jobs.

Installation

pacman -S postfix      # Arch Linux
apt install postfix    # Debian / Ubuntu
dnf install postfix    # Fedora / RHEL

Gmail App Password (required since 2022)

Google removed Basic Authentication ("less secure apps") in May 2022. Your regular Gmail password will be rejected. You need an App Password instead:

  1. Enable 2-Step Verification at myaccount.google.com/security
  2. Go to myaccount.google.com/apppasswords
  3. Create a new App Password — you will get a 16-character code
  4. Use that code in place of your regular password below

Configuration

Create the credentials file:

sudo vim /etc/postfix/sasl_passwd

Add this line:

smtp.gmail.com:587 [email protected]:YOUR_APP_PASSWORD

Hash it:

sudo postmap /etc/postfix/sasl_passwd

Edit /etc/postfix/main.cf and add:

inet_interfaces = localhost
relayhost=smtp.gmail.com:587
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
smtp_use_tls=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom

inet_interfaces = localhost prevents your Postfix from accepting connections from outside — it will only relay mail sent from the local machine, which is what you want.

Start and enable the service

sudo systemctl enable --now postfix

Configure your email client or scripts

Point your mail client or script to localhost port 25. For cron job notifications, set MAILTO at the top of your crontab and they will relay through Gmail automatically.


Last edit on: March 16, 2012

Last updated on: July 3, 2026

By: Guillermo Garron