jeboehm / docker-mailserver

Docker Mailserver based on the famous ISPMail guide
MIT License
371 stars 97 forks source link

Add authentication to smtp relay host #204

Closed Bonno closed 2 months ago

Bonno commented 2 years ago

I've added configuration to provide TLS SMTP authentication for relayhosts. This is necessary when using gmail as relayhost for your mailserver for example. To make use of the TLS authentication you need to follow these steps:

  1. Create a config file './config/mta/sasl_passwd' with the following contents: [smtp.gmail.com]:587 username:password

  2. Add the following volume to 'docker-compose.override.yml' for the 'mta' service: ./config/mta/sasl_passwd:/etc/postfix/sasl_passwd

  3. Add the following lines to your '.env' file

    RELAYHOST=[smtp.gmail.com]:587
    RELAY_PASSWD_FILE=/etc/postfix/sasl_passwd
    RELAY_OPTIONS=
jeboehm commented 2 years ago

Hi @Bonno thank you very much for your contribution! What I'm missing is test coverage to see the authentication working. Could you add a case for that please?

Bonno commented 1 year ago

I'm not sure how to create tests for an authentication flow.

tiberios1 commented 2 months ago

@Bonno @jeboehm is this now abandoned? I'm hoping not as it's something I now need. I'd like to help, but I have no idea how to write the test, although I'm willing to try to learn if someone can point me in the right direction.

jeboehm commented 2 months ago

Hi @tiberios1 no, not abandoned. But the usual lack of time... :) I'm sorry!

tiberios1 commented 2 months ago

Totally understand the lack of time issue. Any chance you can give me some detail as to what needs doing and I'll see if I can help out?

jeboehm commented 2 months ago

Hi @tiberios1 Thanks for your understanding! The relay host scenario is tested here: https://github.com/jeboehm/docker-mailserver/blob/main/test/rootfs/usr/share/tests/080_relayhost.bats

https://github.com/jeboehm/docker-mailserver/blob/main/.github/workflows/integration-tests.yml describes, how tests are executed. In your case:

An instance of mailhog is started (defined in https://github.com/jeboehm/docker-mailserver/blob/main/docker-compose.test.yml) and used to fake an external relay host. Problem here: mailhog doesn't support SMTP authentication.

I think mailpit is a good alternative for mailhog, as it supports smtp auth.

I hope this helps!

Bonno commented 2 months ago

Thanks to the breakdown from @jeboehm I was able to change a few bits and now we have a successful test scenario for this PR.

jeboehm commented 2 months ago

Hi @Bonno awesome! Thanks for your work!

Merged.