emailing the content of the current page

46 views
Skip to first unread message

Vlad

unread,
Jun 20, 2019, 1:07:34 AM6/20/19
to web2py-users
I'd like to send an email with html content - the current page:

mail.send('y...@example.com', 'Message subject', '<html>html body</html>')

How do I make the html body available in python code? (i.e. how do I pass it from the view to the python code?)

to get it in js easy - document.documentElement.outerHTML - but it's a long thing, just args and vars presumably won't work. 

what would be the best way to pass it over / to make it available in the code in order to send by email? 

p.s. I don't want to render page the again, as it has been already rendered; otherwise response.render would be an option... 

Val K

unread,
Jun 20, 2019, 6:23:55 AM6/20/19
to web...@googlegroups.com
I think you can try to yield rendered view from controller just by 'return rendered_response'. If controller returns string (not dict) it will be sent as is

Val K

unread,
Jun 20, 2019, 7:12:13 AM6/20/19
to web2py-users
Also you can hack wsgihandler.py to catch rendered response

Vlad

unread,
Jun 20, 2019, 1:26:33 PM6/20/19
to web2py-users
I couldn't figure out how this woks, so just rendered it again. Not a big deal - just a matter of convenience. The email requests come occasionally, so this extra render doesn't cause trouble. 

Thank you, Val!

Val K

unread,
Jun 20, 2019, 1:39:45 PM6/20/19
to web2py-users
I mean the following logic:
def foo():
    ...
    ret = dict(...)
    if email_required:
        html = response.render(ret)
        ... # send html by email
        return html
    return ret    

Eliezer (Vlad) Tseytkin

unread,
Jun 20, 2019, 1:48:58 PM6/20/19
to web...@googlegroups.com
oops
got it! 
changing it right now! 
simple and brilliant, as always :) 

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/kb42uKUVs6E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/da397328-7304-49f7-a6a6-c9588f54d8ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Val K

unread,
Jun 20, 2019, 2:07:29 PM6/20/19
to web2py-users
#pretty decorator
def with_email_to(addr):
    def inner(f):
        def emailer():
            ret = f()
            html = response.render(ret)
            ... # send html to addr by email
            return html
        return emailer
    return inner

@with_email_to('jo...@google.com')
def foo():
    ...




On Thursday, June 20, 2019 at 8:39:45 PM UTC+3, Val K wrote:
I mean the following logic:
def foo():
    ...
    ret = dict(...)
    if email_required:
        html = response.render(ret)
        ... # send html by email
        return html
    return ret    



On Thursday, June 20, 2019 at 8:26:33 PM UTC+3, Vlad wrote:
I couldn't figure out how this woks, so just rendered it again. Not a big deal - just a matter of convenience. The email requests come occasionally, so this extra render doesn't cause trouble. 

Thank you, Val!

On Thursday, June 20, 2019 at 6:23:55 AM UTC-4, Val K wrote:
I think you can try to yield rendered view from controller just by 'return rendered_response'. If controller returns string (not dict) it will be sent as is
To unsubscribe from this group and all its topics, send an email to web...@googlegroups.com.

Eliezer (Vlad) Tseytkin

unread,
Jun 20, 2019, 2:25:23 PM6/20/19
to web...@googlegroups.com
this is simply awesome! 
thank you ! 

To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/833e8180-b48e-44de-80db-78e91a15a4a5%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages