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.


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.

1 Like

Hi there, I’ve just tried and it’s working well with Mailjet SMTP. Thanks @kanhu!
Just one thing : email sent to Gmail gets into “updates” tab and not “primary”. This because it’s a transactional email service and they inject a pixel to track their emails…

I’ve sent them a message to ask if there’s a way to disable this rather dubious technique and if they can let me send email just how they are without injecting some shit into it. Will get back here to report :wink:


So it’s possible to deactivate this tracking pixel in Mailjet’s settings. I’m not sure it gets still in primary inbox but all people I wrote to lastly received it without any pain. It’s kind of nonsense to set up a selfhosted mail server if smtp is external but for the moment, I haven’t found a better solution to increase deliverability. Cheers


Hello there,
quick feedback here as I was getting [RCPT from unknown 454 4.7.1 Relay access denied] today when seting this configuration as usual with Mailjet.

After a while and a bit of luck what solved it was to put in main.cf relayhost = in-v3.mailjet.com without adding port. When I was adding “:25” or “:465” it was not working.

1 Like

Hi @ImaCrea, I also use mailjet as an external SMTP server.
Did you setup your relay using the standard yunohost commands as stated here ?

Seems like you did start using an exernal SMTP server before it was officially managed by Yunohost.
So maybe there is now a conflict between your current setup and Yunohost internal relay management ?

But it’s true that I don’t put any port number either.

I am posting an update that worked for me for others who are considering a solution.

I managed to set up outgoing emails with G Suite legacy free edition using the following article and Configure SMTP relay | Yunohost Documentation and enabling ‘less secure apps’. I used normal Gmail SMTP server settings.

Ahhh… Yes I did it when it wasn’t supported “officially”

Thanks for this walkthrough.

I added an SMTP server by changing my DNS records at my registrar.

Which method of adding a SMTP relay would be more ideal - this way you showed us, or directly editing DNS entries on your external domain?

just an addon to this procedure : I’ve done it and had an error at each step :

postmap: fatal: open /etc/postfix/sasl_passwd.db: Permission denied

the file was with postfix:root owner, so after changing it to root:root it worked

thanks !