Support for HTML Bodies in Auth.send

12 views
Skip to first unread message

Hadi Zarkoob

unread,
Nov 21, 2025, 11:08:57 PM (13 days ago) Nov 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 PM (13 days ago) Nov 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 PM (13 days ago) Nov 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

Reply all
Reply to author
Forward
0 new messages