Skip to content

Commit

Permalink
Merge pull request #3355 from rtfd/more-mail-changes
Browse files Browse the repository at this point in the history
Email sending: Allow kwargs for other options
  • Loading branch information
ericholscher authored Dec 4, 2017
2 parents bdd93a7 + 86994bc commit 76dbd45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions readthedocs/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@


@app.task(queue='web', time_limit=EMAIL_TIME_LIMIT)
def send_email_task(recipient, subject, template, template_html, context=None, from_email=None):
def send_email_task(recipient, subject, template, template_html,
context=None, from_email=None, **kwargs):
"""Send multipart email
recipient
Expand All @@ -34,12 +35,16 @@ def send_email_task(recipient, subject, template, template_html, context=None, f
context
A dictionary to pass into the template calls
kwargs
Additional options to the EmailMultiAlternatives option.
"""
msg = EmailMultiAlternatives(
subject,
get_template(template).render(context),
from_email or settings.DEFAULT_FROM_EMAIL,
[recipient]
[recipient],
**kwargs
)
try:
msg.attach_alternative(get_template(template_html).render(context),
Expand Down
5 changes: 3 additions & 2 deletions readthedocs/core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def trigger_build(project, version=None, record=True, force=False, basic=False):


def send_email(recipient, subject, template, template_html, context=None,
request=None, from_email=None): # pylint: disable=unused-argument
request=None, from_email=None, **kwargs): # pylint: disable=unused-argument
"""Alter context passed in and call email send task
.. seealso::
Expand All @@ -147,7 +147,8 @@ def send_email(recipient, subject, template, template_html, context=None,
context['uri'] = '{scheme}://{host}'.format(
scheme='https', host=settings.PRODUCTION_DOMAIN)
send_email_task.delay(recipient=recipient, subject=subject, template=template,
template_html=template_html, context=context, from_email=from_email)
template_html=template_html, context=context, from_email=from_email,
**kwargs)


def slugify(value, *args, **kwargs):
Expand Down

0 comments on commit 76dbd45

Please sign in to comment.