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

[DONE] add NOTIFY_SENDER boolean parameter #1192

Merged
merged 11 commits into from
Sep 23, 2024
13 changes: 13 additions & 0 deletions pod/main/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -3915,6 +3915,19 @@
"pod_version_end": "",
"pod_version_init": "3.1"
},
"NOTIFY_SENDER": {
"default_value": "True",
"description": {
"en": [
"In unauthenticated mode, when using the contact form, sends a copy of the message to the address entered in the form."
],
"fr": [
"En mode non authentifié, lors de l'utilisation du formulaire de contact, envoie une copie du message à l'adresse saisie dans le formulaire."
]
},
"pod_version_end": "",
"pod_version_init": "3.8.2"
},
"SERVER_EMAIL": {
"default_value": "noreply",
"description": {
Expand Down
36 changes: 19 additions & 17 deletions pod/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
[mail for name, mail in getattr(settings, "MANAGERS")],
)
DEFAULT_FROM_EMAIL = getattr(settings, "DEFAULT_FROM_EMAIL", "[email protected]")
NOTIFY_SENDER = getattr(settings, "NOTIFY_SENDER", True)
USER_CONTACT_EMAIL_CASE = getattr(settings, "USER_CONTACT_EMAIL_CASE", [])
CUSTOM_CONTACT_US = getattr(settings, "CUSTOM_CONTACT_US", False)
MANAGERS = getattr(settings, "MANAGERS", [])
Expand Down Expand Up @@ -281,24 +282,25 @@ def contact_us(request):
msg.send(fail_silently=False)

# EMAIL TO SENDER
subject = "[ %s ] %s %s" % (
__TITLE_SITE__,
_("your message untitled"),
dict(SUBJECT_CHOICES)[form_subject],
)
if NOTIFY_SENDER:
subject = "[ %s ] %s %s" % (
__TITLE_SITE__,
_("your message untitled"),
dict(SUBJECT_CHOICES)[form_subject],
)

html_content = loader.get_template("mail/mail_sender.html").render(
{
"TITLE_SITE": __TITLE_SITE__,
"message": message.replace("\n", "<br>"),
}
)
text_content = bleach.clean(html_content, tags=[], strip=True)
msg = EmailMultiAlternatives(
subject, text_content, DEFAULT_FROM_EMAIL, [email]
)
msg.attach_alternative(html_content, "text/html")
msg.send(fail_silently=False)
html_content = loader.get_template("mail/mail_sender.html").render(
{
"TITLE_SITE": __TITLE_SITE__,
"message": message.replace("\n", "<br>"),
}
)
text_content = bleach.clean(html_content, tags=[], strip=True)
msg = EmailMultiAlternatives(
subject, text_content, DEFAULT_FROM_EMAIL, [email]
)
msg.attach_alternative(html_content, "text/html")
msg.send(fail_silently=False)

messages.add_message(request, messages.INFO, _("Your message has been sent."))

Expand Down
Loading