mailer: set name in sender and reply to

pull/73/head
Christian Merten 1 year ago
parent 5cee496662
commit 32e361151f
Signed by: christian.merten
GPG Key ID: D953D69721B948B3

@ -14,3 +14,4 @@ CELERY_EMAIL_TASK_CONFIG = {
} }
DEFAULT_SENDING_MAIL = os.environ.get('EMAIL_SENDING_ADDRESS', 'django@localhost') DEFAULT_SENDING_MAIL = os.environ.get('EMAIL_SENDING_ADDRESS', 'django@localhost')
DEFAULT_SENDING_NAME = os.environ.get('EMAIL_SENDING_NAME', 'Kompass')

@ -19,6 +19,8 @@ def send(subject, content, sender, recipients, message_id=None, reply_to=None,
kwargs = {"reply_to": reply_to} kwargs = {"reply_to": reply_to}
else: else:
kwargs = {} kwargs = {}
if sender == settings.DEFAULT_SENDING_MAIL:
sender = addr_with_name(settings.DEFAULT_SENDING_MAIL, settings.DEFAULT_SENDING_NAME)
url = prepend_base_url("/newsletter/unsubscribe") url = prepend_base_url("/newsletter/unsubscribe")
headers = {'List-Unsubscribe': '<{unsubscribe_url}>'.format(unsubscribe_url=url)} headers = {'List-Unsubscribe': '<{unsubscribe_url}>'.format(unsubscribe_url=url)}
if message_id is not None: if message_id is not None:
@ -89,3 +91,7 @@ def get_invite_as_user_key(key):
def prepend_base_url(absolutelink): def prepend_base_url(absolutelink):
return "{protocol}://{base}{link}".format(protocol=settings.PROTOCOL, base=settings.BASE_URL, link=absolutelink) return "{protocol}://{base}{link}".format(protocol=settings.PROTOCOL, base=settings.BASE_URL, link=absolutelink)
def addr_with_name(addr, name):
return "{name} <{addr}>".format(name=name, addr=addr)

@ -3,7 +3,8 @@ from django.core.exceptions import ValidationError
from django import forms from django import forms
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext from django.utils.translation import gettext
from .mailutils import send, get_content, NOT_SENT, SENT, PARTLY_SENT from .mailutils import send, get_content, NOT_SENT, SENT, PARTLY_SENT,\
addr_with_name
from utils import RestrictedFileField from utils import RestrictedFileField
from jdav_web.celery import app from jdav_web.celery import app
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
@ -159,15 +160,17 @@ class Message(CommonModel):
# set correct from address # set correct from address
# if the sender is none or if sending from association emails has been # if the sender is none or if sending from association emails has been
# disabled, use the default sending mail # disabled, use the default sending mail
if sender is None or not settings.SEND_FROM_ASSOCIATION_EMAIL: if sender is None:
from_addr = settings.DEFAULT_SENDING_MAIL from_addr = addr_with_name(settings.DEFAULT_SENDING_MAIL, settings.DEFAULT_SENDING_NAME)
elif sender and settings.SEND_FROM_ASSOCIATION_EMAIL:
from_addr = addr_with_name(sender.association_email, sender.name)
else: else:
from_addr = sender.association_email from_addr = addr_with_name(settings.DEFAULT_SENDING_MAIL, sender.name)
# if sending from the association email has been disabled, # if sending from the association email has been disabled,
# a sender was supplied and the reply to is empty, add the sender's # a sender was supplied and the reply to is empty, add the sender's
# DAV360 email as reply to # DAV360 email as reply to
if sender and not settings.SEND_FROM_ASSOCIATION_EMAIL and sender.has_internal_email() and reply_to == []: if sender and not settings.SEND_FROM_ASSOCIATION_EMAIL and sender.has_internal_email() and reply_to == []:
reply_to.append(sender.email) reply_to.append(addr_with_name(sender.email, sender.name))
try: try:
success = send(self.subject, get_content(self.content, registration_complete=True), success = send(self.subject, get_content(self.content, registration_complete=True),
from_addr, from_addr,

Loading…
Cancel
Save