Introduction

Some time ago I tried to configure a SMTP server in a host in the cloud, but because of some restrictions, the emails from that server were bounced. The problem was that the hosting provider didn’t configure the PTR DNS entries (more about DNS PTR entries) for some kind of hostings.

When this happens the best solution is to use a SMTP relay server, by this way that server is in charge of the final delivery of the emails. There are some services such us Sendinblue which offers 300 mails per day in the free plan. I believe it’s enough for a normal use of a mail server.

I will use Sendinblue for this post, however it could be use any other external SMTP server.

Sendinblue

The first step is to register in the Sendinblue service. Once registered you have to create a SMTP key (Tab SMTP). Save that key because it will be used after.

Postfix

Installation

The first step is to install Postfix. It is a free and open-source MTA (Mail Transfer Agent) which routes and delivers electronic mail (e-mails).

To install just use this command:

sudo apt install postfix

Then you’ll receive a prompt asking the General type of mail configuration. Select Internet Site from the options. Next step you’ll have to enter the FQDN of your server.

Configure SMTP users and Passwords

Next step is to configure the parameters of Sendinblue (Remember, the username, and the key I ask you to save before).

sudo vi /etc/postfix/sasl_passwd

And I add the key with that format (change the e-mail address)

[smtp-relay.sendinblue.com]:587 admin@oastic.com:xsmtpsib-f9e38e034b5a4fcfa5b3061e1252f23f15f63d55b8241a421ec62877be6f967c-aJ70ykx5VQ13PgSs

And now it has to be needed to create the Postfix lookup table.

sudo postmap /etc/postfix/sasl_passwd

Next step is to assign the correct permissions and owner of the file.

sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

Configure Relay Host in Postfix

Edit the mail.cffile:

# sudo vi /etc/postfix/main.cf

And add these lines:

relayhost = [smtp-relay.sendinblue.com]:587 
# enable SASL authentication
smtp_sasl_auth_enable = yes
# disallow methods that allow anonymous authentication.
smtp_sasl_security_options = noanonymous
# where to find sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# Enable STARTTLS encryption
smtp_use_tls = yes
# where to find CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

And finally, reload the Postfix Service.

service postfix reload

Configure FQDN

To configure the FQDN it is needed to edit the Operating System /etc/hosts file.

sudo vi /etc/hosts

It is needed to add a new line with the IP address 127.0.1.1 with the hostname and the FQDN. In my case with the domain oastic.com this should be the line added:

127.0.1.1 myhost myhost.oastic.com

Testing FQDN

A way to check the value of the FQDN is to use the hostname command. Without options, it will return the hostname:

# hostname
myhost

And with the --fqdn parameter, you’ll have the complete FQDN.

# hostname --fqdn
myhost.oastic.com

Testing mail delivery

For testing the mail remote deilvery we are going to use the mail command.

# mail mytestaccount@gmail.com
Cc:
Subject: Test
Test
#

(Control+D to finish)

And now the e-mail should have been delivered using the *Sendinblue relay mail server.

I suggest to check the /var/log/mail.log file to check the status of the e-mail. In my case it is sent, so it is OK.

2022-11-10T22:58:37.133171+01:00 myhost postfix/pickup[58673]: 203AC21AD6: uid=1000 from=<root>
2022-11-10T22:58:37.147450+01:00 myhost postfix/cleanup[59096]: 203AC21AD6: message-id=<20221110215837.203AC21AD6@myhost>
2022-11-10T22:58:37.154150+01:00 myhost postfix/qmgr[58672]: 203AC21AD6: from=<root@myhost.oastic.com>, size=379, nrcpt=1 (queue active)
2022-11-10T22:58:37.825501+01:00 myhost postfix/smtp[59098]: 203AC21AD6: to=<mytestaccountgmail.com>, relay=smtp-relay.sendinblue.com[185.107.232.248]:587, delay=0.71, delays=0.04/0.14/0.42/0.12, dsn=2.0.0, status=sent (250 Message queued as <20221110215837.203AC21AD6@medusa>)
2022-11-10T22:58:37.826058+01:00 myhost postfix/qmgr[58672]: 203AC21AD6: removed

And that’s all. I hope you enjoyed this post :-)