feat: add necessary bits to rewrite sender and recipient for external relay

This commit is contained in:
VC
2024-07-05 11:53:34 +02:00
parent 3faef4717a
commit 19f800b796
4 changed files with 28 additions and 4 deletions

View File

@@ -4,6 +4,11 @@
file: stunnel.yml file: stunnel.yml
when: smtprelay_port not in [587] when: smtprelay_port not in [587]
- name: Include SMTP remapping
ansible.builtin.include_tasks:
file: smtp_remap.yml
when: smtprelay_origin not in ["mateu.be"]
- name: Install postfix smtp server - name: Install postfix smtp server
ansible.builtin.package: ansible.builtin.package:
name: postfix name: postfix

View File

@@ -0,0 +1,12 @@
---
- name: "Create {{ item.destination }}"
ansible.builtin.copy:
dest: "{{ item.destination }}"
mode: 0644
content: |
{{ item.content }}
loop:
- {destination: "/etc/postfix/recipient_canonical", content: "/.+/ root@mateu.be"}
- {destination: "/etc/postfix/header_check", content: "/From:.*/ REPLACE From: root@{{ smtprelay_origin }}"}
- {destination: "/etc/postfix/sender_canonical_maps", content: "/.+/ root@{{ smtprelay_origin }}"}

View File

@@ -1,21 +1,21 @@
--- ---
- name: Install stunnel - name: Install stunnel
package: ansible.builtin.package:
name: stunnel4 name: stunnel4
state: present state: present
- name: SMTP wrapper - name: SMTP wrapper
template: ansible.builtin.template:
src: smtp-wrapper.conf.j2 src: smtp-wrapper.conf.j2
dest: /etc/stunnel/smtp-wrapper.conf dest: /etc/stunnel/smtp-wrapper.conf
mode: 0644 mode: 0644
notify: Restart stunnel4 notify: Restart stunnel4
- name: Rewrite var smtprelay_host - name: Rewrite var smtprelay_host
set_fact: ansible.builtin.set_fact:
smtprelay_host: "localhost" smtprelay_host: "localhost"
- name: Rewrite var smtprelay_port - name: Rewrite var smtprelay_port
set_fact: ansible.builtin.set_fact:
smtprelay_port: "2{{ smtprelay_port }}" smtprelay_port: "2{{ smtprelay_port }}"

View File

@@ -8,6 +8,13 @@ myorigin = {{ smtprelay_origin }}
# Uncomment the next line to generate "delayed mail" warnings # Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h #delay_warning_time = 4h
{% if smtprelay_origin not in ["mateu.be"] %}
recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical
sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps = regexp:/etc/postfix/sender_canonical_maps
smtp_header_checks = regexp:/etc/postfix/header_check
{% endif %}
alias_maps = hash:/etc/aliases alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases alias_database = hash:/etc/aliases
mydestination = $myhostname, localhost.$mydomain, localhost mydestination = $myhostname, localhost.$mydomain, localhost