[enh] Allow admin to specify an smtp relay

This commit is contained in:
ljf 2019-08-13 22:49:01 +02:00 committed by ljf
parent 42bc8c354a
commit 64066f85b0
3 changed files with 35 additions and 1 deletions

View file

@ -24,6 +24,16 @@ do_pre_regen() {
# Support different strategy for security configurations # Support different strategy for security configurations
export compatibility="$(yunohost settings get 'security.postfix.compatibility')" export compatibility="$(yunohost settings get 'security.postfix.compatibility')"
# Add possibility to specify a relay
# Could be useful with some isp with no 25 port open or more complex setup
export relay_host="$(yunohost settings get 'smtp.relay.host')"
if [ ! -z "${relay_host}" ]; then
export relay_port="$(yunohost settings get 'smtp.relay.port')"
export relay_user="$(yunohost settings get 'smtp.relay.user')"
relay_password="$(yunohost settings get 'smtp.relay.password')"
echo "[${relay_host}]:${relay_port} ${relay_user}:${relay_password}" > /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
fi
export main_domain export main_domain
export domain_list="$YNH_DOMAINS" export domain_list="$YNH_DOMAINS"
ynh_render_template "main.cf" "${postfix_dir}/main.cf" ynh_render_template "main.cf" "${postfix_dir}/main.cf"

View file

@ -72,7 +72,11 @@ alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases alias_database = hash:/etc/aliases
mydomain = {{ main_domain }} mydomain = {{ main_domain }}
mydestination = localhost mydestination = localhost
{% if relay_host == "" %}
relayhost = relayhost =
{% else %}
relayhost = [{{ relay_host }}]:{{ relay_port }}
{% endif %}
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION" mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0 mailbox_size_limit = 0
@ -178,3 +182,19 @@ default_destination_rate_delay = 5s
# So it's easly possible to scan a server to know which email adress is valid # So it's easly possible to scan a server to know which email adress is valid
# and after to send spam # and after to send spam
disable_vrfy_command = yes disable_vrfy_command = yes
{% if relay_user != "" %}
# Relay email through an other smtp account
# enable SASL authentication
smtp_sasl_auth_enable = yes
# disallow methods that allow anonymous authentication.
smtp_sasl_security_options = noanonymous
# where to find sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
{% if relay_port == "587" %}
# Enable STARTTLS encryption
smtp_use_tls = yes
{% endif %}
# where to find CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
{% endif %}

View file

@ -71,6 +71,10 @@ DEFAULTS = OrderedDict([
"choices": ["intermediate", "modern"]}), "choices": ["intermediate", "modern"]}),
("pop3.enabled", {"type": "bool", "default": False}), ("pop3.enabled", {"type": "bool", "default": False}),
("smtp.allow_ipv6", {"type": "bool", "default": True}), ("smtp.allow_ipv6", {"type": "bool", "default": True}),
("smtp.relay.host", {"type": "string", "default": ""}),
("smtp.relay.port", {"type": "int", "default": 587}),
("smtp.relay.user", {"type": "string", "default": ""}),
("smtp.relay.password", {"type": "string", "default": ""}),
]) ])