Skip to content

Commit

Permalink
Merge pull request #59 from collective/custom_subject
Browse files Browse the repository at this point in the history
Configurable email subject
  • Loading branch information
folix-01 committed Jun 28, 2024
2 parents 9f66f44 + 03cc1e3 commit fdda036
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Changelog
2.7.1 (unreleased)
------------------

- Configurable mail header and footer
- Configurable email subject.
[folix-01]

- Configurable mail header and footer.
[folix-01]

2.7.0 (2023-04-03)
Expand Down
7 changes: 6 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:target: https://pypi.python.org/pypi/collective.volto.formsupport
:alt: Egg Status

.. image:: https://img.shields.io/pypi/pyversions/collective.volto.formsupport.svg?style=plastic
.. image:: https://img.shields.io/pypi/pyversions/collective.volto.formsupport.svg?style=plastic
:target: https://pypi.python.org/pypi/collective.volto.formsupport/
:alt: Supported - Python Versions

Expand Down Expand Up @@ -197,6 +197,11 @@ By default this is not set.

The upload limit is also passed to the frontend in the form data with the `attachments_limit` key.

Email subject templating
========================
You can also interpolate the form values to email subject using the field id, in this way: ${123321123}


Content-transfer-encoding
=========================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,25 @@ def get_bcc(self):
bcc.append(data["value"])
return bcc

def send_data(self):
def get_subject(self):
subject = self.form_data.get("subject", "") or self.block.get(
"default_subject", ""
)

for i in self.form_data.get("data", []):
field_id = i.get("field_id")

if not field_id:
continue

subject = subject.replace("${" + i.get("field_id") + "}", i.get("value"))

return subject

def send_data(self):

subject = self.get_subject()

mfrom = self.form_data.get("from", "") or self.block.get("default_from", "")
mreply_to = self.get_reply_to()

Expand Down

0 comments on commit fdda036

Please sign in to comment.