bokysan / docker-postfix

Multi architecture simple SMTP server (postfix null relay) host for your Docker and Kubernetes containers. Based on Debian/Ubuntu/Alpine.
MIT License
555 stars 152 forks source link

Relaying through Mailgun for multiple domains and username/passwords #194

Closed sujitph closed 7 months ago

sujitph commented 7 months ago

Hi there,

This is not an issue, more of a question. I am sure I am doing something wrong.

I am trying to relay the mail through Mailgun. I have 3 domains added in my mailgun account and unfortunately mailgun gives separate username/password for each domain for SMTP authentication. I believe you can configure the postfix to use different username/password based on the sending domain.

This is how I've setup my docker run command. Unfortunately, while relaying it not using the username and password from the sasl_passwd file and mailgun is rejecting the request. Can anyone share what am I doing wrong?

docker run --rm --name postfix-mailgun -p 1587:587
-e RELAYHOST="[smtp.mailgun.org]:587"
-e ALLOW_EMPTY_SENDER_DOMAINS=true
-e POSTFIX_sender_dependent_relayhost_maps:"lmdb:/etc/postfix/sender_dependent_relayhost"
-e POSTFIX_smtp_sasl_auth_enable:"yes"
-e POSTFIX_smtp_sasl_password_maps:"lmdb:/etc/postfix/sasl_passwd"
-e POSTFIX_smtp_tls_security_level="encrypt"
-v ./postfix/sasl_passwd:/etc/postfix/sasl_passwd
-v ./postfix/sender_dependent_relayhost:/etc/postfix/sender_dependent_relayhost
boky/postfix


Content of /etc/postfix/sasl_passwd

@domain.com abc@mg.domain.com:password
@domain.net abc@mg.domain.net:password


Content of /etc/postfix/sender_dependent_relayhost

@domain.com [smtp.mailgun.org]:587
@domain.net [smtp.mailgun.org]:587
bokysan commented 7 months ago

Hi,

this project is not a generic Postfix help tool. To do that you need to look at the documentation elsewhere. I'd be happy to help, but simply cannot answer every Postfix question on my own time.

That being said, I am using a similar configuration and I might be able to point you in the right direction.

My configuration is as follows:

POSTFIX_sender_dependent_relayhost_maps: "lmdb:/etc/postfix/sender_dependent_relayhost"
POSTFIX_smtp_sasl_auth_enable: "yes"
POSTFIX_smtp_sasl_password_maps: "lmdb:/etc/postfix/sasl_password"
POSTFIX_smtp_sender_dependent_authentication: "yes"
POSTFIX_smtp_sasl_security_options: "noanonymous"
POSTFIX_smtp_tls_policy_maps = "lmdb:/etc/postfix/smtp_tls_policy"

Then in sasl_password:

<email>             <username>:<password>
<email>             <username>:<password>
<email>             <username>:<password>
...

in sender_dependent_relayhost:

<email>            [<host>]:<port>
<email>            [<host>]:<port>
<email>            [<host>]:<port>
...
@<domain>          [<host>]:<port>
@<domain>          [<host>]:<port>
@<domain>          [<host>]:<port>
...

in smtp_tls_policy:

[<server>]:<port>           encrypt
...
[smtp.gmail.com]:587        secure
.google.com:587             secure
.googlemail.com:587         secure
[127.0.0.2]:20025           none
...

I suggest checking out Mail station example as well.

Hope this helps.

Cheers, B