External SMTP relay server for the domain

I have the main DNS domain of my YunoHost instance managed by a hosting provider (Gandi.net), and I am also using the smtp that the provider offers, from a long time, before I used YunoHost.

I would like to “bypass” the smtp server included in YunoHost, so that all the mails it is told to send are relayed through the Gandi server. This way, when any of the apps needs to send an email they can do it with no aditional configuration, by using only the local smtp, but the actual email operation is done in the Gandi server, that is working ok and is very reliable for me. When other people send emails to the domain they will be kept in Gandi server, and will not reach YunoHost (we don’t need the personal mailboxes for our users, at least for now).

Would something like this be possible? I think so, but it is a long time since I last configured a postfix instance, and don’t remember how to do it. Besides, I fear that I could broke some of the automatic YunoHost configuration.

Any advice? Thanks.

  1. Edit /etc/postfix/main.cf

  2. Add these lines:
    smtp_sasl_auth_enable = yes
    smtp_sasl_security_options = noanonymous
    smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
    smtp_always_send_ehlo = yes
    relayhost = smtp.domain.tld

Change the smtp.domain.tld with your providers SMTP and add port if the port SMTP is different. Eg. relayhost = smtp.your_domain.tld:port

  1. Create a file saslpasswd in /etc/postix. Eg. /etc/postfix/saslpasswd

  2. Add your username and password in saslpasswd in following format.

    smtp.domain.tld yourlogin:yourpassword

  3. Hash saslpasswd with following command.

    $ postmap /etc/postfix/saslpasswd

  4. Restart postfix.

    $ service postfix restart

That’s it

Test it and see the postfix logs for the relay traces.

Note: When the Yunohost gets updated you will have to configure /etc/postfix/main.cf again as Yunohost update will overwrite this file.

You can even relay from your friends Yunohost server too.

1 Like

Thanks very much! I’ll try it and tell you if it works :smiley:

I have just found this tutorial, that at first I thought that was for this same issue, but now I think not. What do you think? Is somehow related to it? I don’t understand it well:

Try @kanhu proposition, it’s closer to your needs I think.

Yes, indeed! Thanks

That’s it

Thanks @kanhu, this was very helpful.