You can configure Postfix MTA to use as a Smarthost i.e. routing all mails to a smarthost. A smarthost can be an external smtpd server provided by SendGrid, AWS, Rackspace, Google apps/Gmail, ISP or your own server in another data center with the help of the relay server.

sudo dpkg-reconfigure postfix


sudo nano /etc/postfix/main.cf

Set myhostname to FQDN

=====
myhostname = websrv.example.com

# Enable auth
smtp_sasl_auth_enable = yes
# Set username and password
smtp_sasl_password_maps = static:YOUR-SMTP-USER-NAME-HERE:YOUR-SMTP-SERVER-PASSWORD-HERE
smtp_sasl_security_options = noanonymous
# Turn on tls encryption 
smtp_tls_security_level = encrypt
header_size_limit = 4096000
# Set external SMTP relay host here IP or hostname accepted along with a port number. 
relayhost = [YOUR-SMTP-SERVER-IP-HERE]:587
# accept email from our web-server only 
inet_interfaces = 127.0.0.1
=====

sudo systemctl stop postfix

sudo systemctl start postfix


Verify that TCP port #25 is in listing state on 127.0.0.1:

sudo apt install net-tools

netstat -tulpn | grep :25


Send a test mail using Postfix the relay server:

echo "This is a test email body." | mail -s "Subject" -a "From: webmaster@example.com" you@example.com


sudo tail -f /var/log/mail.log


mailname:
example.com

aliases:
root: $USER@websrv
sudo newaliases

hosts:
127.0.1.1    websrv.example.com websrv
Living in Tune with Nature's Beat (Earth, Water, Fire, Air, Space)

Leave a Reply

Your email address will not be published. Required fields are marked *