Introduction

If you're hosting websites or mail services using aaPanel and want to route all outgoing emails through a third-party SMTP relay like relay.stacksmtp.com, this guide will help you set up a secure and authenticated SMTP relay (smarthost).

Prerequisites

  • Hostname of the SMTP relay — e.g., relay.stacksmtp.com
  • Valid SMTP credentials (username and password)
  • Port 587 or 465 open in the server's firewall
  • Root SSH access to your aaPanel server
  • Postfix installed and configured as MTA (you can confirm this from Mail Server settings)

Step 1: SSH Into Your Server

Connect via SSH as root:

ssh root@your_server_ip

Step 2: Install Required Packages

Install Postfix helpers for SASL auth and mail testing:

apt update
apt install mailutils libsasl2-modules -y

For CentOS/RHEL:

yum install postfix cyrus-sasl-plain mailx -y

Step 3: Edit Postfix Configuration

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

relayhost = [relay.stacksmtp.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Step 4: Add SMTP Authentication Credentials

Create or edit the credentials file:

nano /etc/postfix/sasl_passwd

Paste:

[relay.stacksmtp.com]:587 your_username:your_password

Then hash and protect the file:

postmap /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

Step 5: Restart Postfix

Apply the changes by restarting Postfix:

systemctl restart postfix

Step 6: Test Email Delivery

Try sending a test message:

echo "This is a test email from aaPanel" | mail -s "SMTP Relay Test" recipient@example.com

Conclusion

You have successfully configured aaPanel to send outgoing emails through an external SMTP relay (smarthost) with full encryption and authentication. This improves deliverability, helps avoid blacklists, and allows you to centralize email handling through relay.stacksmtp.com.

Was this answer helpful? 0 Users Found This Useful (0 Votes)