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 Like
  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.

2 Likes

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:

1 Like

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