Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable email subject #59

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading