An html component cannot be sent with auth email messages

Open
#810 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
html, python

Research direction

Start with the Mailer class in py4web/utils/mailer.py around lines 264-265, then trace the Auth class send method where params.message['body'] is handled. Reproduce an auth message with a two-item body and shortcuts such as {first_name} or {link}; done means both plain-text and HTML components are formatted and sent correctly.

Written by the indexing model from the issue text.

Description

The Mailer class indicates that to send html messages, the message body should be a 2-list or a 2-tuple. I tried setting auth.param.messages['reset_password']['body'] to a list, without success. After spending some time debugging, I think I found the root cause: Even if a list or tuple is provided as the message body, the params.message['body'] ends up being of class pluralize. It is params.message['body'].text that will contain the original list or tuple.

Also, a related issue. Both the plain text and HTML components of the body should be able to interpret shortcuts like {first_name} and {link} in the string.

Here is a quick change to the send method of the Auth class that fixes both the issues above. But it may not be the best solution, because it eliminates the original pluralize class.

if isinstance(message["body"].text, (list, tuple)):
   body = [element.format(**d) for element in message["body"].text]
else:
   body = message["body"].format(**d)
Dominant language
HTML
Stars
319
Forks
144
Avg merge
6d 20h
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from web2py/py4web

All issues in web2py/py4web

Similar issues

More Security issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.