Template rendered html email for Web2py email verification and password reset

For discussion about this old problem, read Google group thread here.

I ended up modifying gluon/tools.py. It is probably not a good practice. But it is the easiest solution.

I edit register() and email_reset_password()

modifying something like (depends on which one)

message=self.messages.verify_email % d

to

message=('',response.render('email/template.html', d))

Be careful with the ending parentheses, the two functions need different number of them due to context codes.

It is important to use a 2-tuple or 2-list to pass the second item to html in the email, the empty '' will go to text. Otherwise, it will likely be sent as plain text, especially if you have <!DOCTYPE as start in your template.

for email_reset_password(), you also need:

response = current.response

Then you need to delete tools.pyc and restart web2py to take effect.

Make sure you modify tools.py and delete tools.pyc every time you update web2py.

Hope this save some other people’s time.