Skip to content

Commit

Permalink
Support List-Unsubscribe header (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: William Di Luigi <[email protected]>
  • Loading branch information
eliasol and wil93 committed Dec 21, 2024
1 parent eaf3ae3 commit 9c17bf8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mailipy/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ def render_template(template, data):
if "reply-to" in config:
msg["Reply-To"] = config["reply-to"]

if "list-unsubscribe" in config:
msg["List-Unsubscribe"] = config["list-unsubscribe"]

msg["Subject"] = config["subject"]
msg["Date"] = email.utils.formatdate()
msg["Message-Id"] = config["msgid"] % (str(int(datetime.datetime.timestamp(datetime.datetime.now()))) + str(random.random()))
Expand Down
2 changes: 2 additions & 0 deletions mailipy/gen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_create_two_emails(tmp_path):
reply-to: "[email protected]"
subject: "Invitation for {{name}}"
msgid: "<%[email protected]>"
list-unsubscribe: "<mailto: [email protected]?subject=Bye>"
attach:
- "test.png"
images:
Expand Down Expand Up @@ -59,6 +60,7 @@ def test_create_two_emails(tmp_path):
assert '[email protected]' in msg['cc']
assert '[email protected]' in msg['bcc']
assert '[email protected]' in msg['reply-to']
assert 'mailto: [email protected]' in msg['list-unsubscribe']

multipart, attachment, embedded_image = msg.get_payload()
plaintext, html = multipart.get_payload()
Expand Down
1 change: 1 addition & 0 deletions sample_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc: []
bcc: []
subject: "Invito per il terzo round di allenamento delle ITACPC 🍕"
msgid: "<%[email protected]>"
list-unsubscribe: "<mailto: [email protected]?subject=Bye>"
attach: []
images:
- path: "./logo.png"
Expand Down

0 comments on commit 9c17bf8

Please sign in to comment.