Support for HTML Bodies in Auth.send

49 views
Skip to first unread message

Hadi Zarkoob

unread,
Nov 21, 2025, 11:08:57 PMNov 21
to py4web
Hi all!

The default body of Auth messages is a plain string. However, it’s common to send HTML bodies as well. 

The current send method in Auth assumes the body is always a string. It would be helpful to update this method so it can also handle bodies that include an HTML component. The required changes are minimal — we just need to allow the body to be either a 2-list or 2-tuple, in addition to a single string.  

This would be an example:

auth.param.messages['verify_email']['body'] = (VERIFY_EMAIL_PLAIN_TEXT, render(
    filename=os.path.join(CURRENT_FILE_FOLDER, "templates/emails/verify_email.html")))

Thanks!
Hadi

Massimo DiPierro

unread,
Nov 21, 2025, 11:27:45 PMNov 21
to Hadi Zarkoob, py4web
Good idea. 
Could we just detect that is starts with <html>?
We already do that in auth.mailer.send so I thought this was already possible

--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/b78ccf9a-4f16-4ae9-9d81-1ff387ef1b42n%40googlegroups.com.

Hadi Zarkoob

unread,
Nov 21, 2025, 11:45:50 PMNov 21
to py4web

Thank you, Massimo. I’m not able to find auth.mailer.send. Did you perhaps mean auth.sender.send?

It looks to me like the key change is to check whether body is a 2-element list or tuple and, if so, apply format(**d) to both elements. I was able to get it working by simply updating this line as follows:

        body = message["body"].format(**d)

to:

    if isinstance(message["body"].text, (list, tuple)):
        body = [element.format(**d) for element in message["body"].text]
    else:
        body = message["body"].format(**d)

The rest is handled by the Mailer library.

Please let me know if any additional information is needed.

Thank you!

Hadi

Massimo DiPierro

unread,
Dec 7, 2025, 9:20:44 PMDec 7
to py4web
Sorry for the delay, this is merged. Please help me check it.

Hadi Zarkoob

unread,
Dec 9, 2025, 12:47:40 AMDec 9
to py4web
Thank you for this!

Looks great, I just think it should be  isinstance(message["body"].text, (list, tuple)) instead of  isinstance(message["body"], (list, tuple)) because message["body"] is of the type pluralize.lazyT not tuple. Does that make sense?

Hadi

Massimo DiPierro

unread,
Dec 9, 2025, 2:34:11 AMDec 9
to py4web
Can you show me an example of how you are using internationalization for the message body? That .text should not be required but I may be missing something

Hadi Zarkoob

unread,
Dec 9, 2025, 3:03:13 AMDec 9
to py4web
I do not use internationalization. It is done, by default, inside auth.py.

Without .text  isinstance(message["body"], (list, tuple)) does not return true even when the user sets the message["body"] to a tuple. The code inside auth.py changes the type from tuple to plurazie.lazyT.

Please let me know if more information is needed.

Thank you,
Hadi

Massimo DiPierro

unread,
Dec 9, 2025, 3:18:00 AMDec 9
to Hadi Zarkoob, py4web
You are right. Now I understand the problem better and I think the solution is a bit different.
I added a commit to master. Can you help me test it?



Message has been deleted
Message has been deleted

Hadi Zarkoob

unread,
Dec 9, 2025, 7:58:37 PMDec 9
to py4web
I just tested it, and everything works great!

I'm glad to see that py4web is becoming quite stable.  

- Hadi

Massimo DiPierro

unread,
Dec 10, 2025, 2:07:36 AMDec 10
to py4web
thank you. releasing 1.20251209.1 with this change
Reply all
Reply to author
Forward
0 new messages