How to relay mail through another YunoHost

One of my yunohost server has been blacklisted by free for several days, Free blacklist email server if there is a big variation of email sent.

In this tuto, I explain how I have used an other yunohost server to relay my mails to Free.

Server A: is the blacklisted server
Server B: The future relay

On Server B

Create a smtp account

Add the domain to yunohost

yunohost domain add YOURDOMAIN.TLD

Create a user with a strong password

yunohost user create relay -f RELAY -l RELAY -m relay@YOURDOMAIN.TLD -p PASSWORD -q 0

Copy dkim key

Take the dkim key in Server A and copy it in Server B
Dkim keys are in /etc/dkim

On Server A

Configure SASL authentication

cd /etc/postfix
echo "SERVER_B.YOURDOMAIN.TLD relay:PASSWORD" > sasl_passwd
postmap sasl_passwd
chmod go=--- sasl_passwd
chmod go=--- sasl_passwd.db

Add a transport file

cd /etc/postfix
echo " smtp:SERVER_B.YOURDOMAIN.TLD" > transport
echo " smtp:SERVER_B.YOURDOMAIN.TLD" > transport
postmap transport
echo "transport_maps = hash:/etc/postfix/transport"  >
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

Restart postfix

service postfix restart


To test you can check the log file on each server:

tail -f /var/log/mail.log