#!/bin/bash echo "=== POSTFIX RELAY SETUP VIA GMAIL SMTP ===" read -p "Enter your Gmail address (sender): " GMAIL read -p "Enter your Gmail App Password (16 characters, no spaces): " APPPASS # 1. Install dependencies echo "→ Installing Postfix and dependencies..." sudo apt update sudo DEBIAN_FRONTEND=noninteractive apt install -y postfix mailutils libsasl2-modules # 2. Create credentials file echo "→ Creating Gmail SMTP credentials file..." echo "[smtp.gmail.com]:587 $GMAIL:$APPPASS" | sudo tee /etc/postfix/sasl_passwd > /dev/null # 3. Secure the credentials file echo "→ Securing sasl_passwd file..." sudo postmap /etc/postfix/sasl_passwd sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db # 4. Backup existing Postfix config echo "→ Backing up original Postfix config to main.cf.bak..." sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.bak # 5. Update Postfix configuration echo "→ Configuring Gmail SMTP relay in Postfix..." sudo sed -i '/^relayhost =/d' /etc/postfix/main.cf sudo tee -a /etc/postfix/main.cf > /dev/null <