Email from text field while preserving the text format

32 views
Skip to first unread message

Serge Bourgeois

unread,
Jun 20, 2017, 12:24:43 PM6/20/17
to web2py-users

I like web2py for the good balance between simplicity and completeness. Most of the time, when I have a question, I can find a response googeling. Today not...

I could cope with attachments, but I'm still struggling with rich text fields for the email body. Using BeautifulSoup.BeautifulSoup(my_field).text removes the tags, but the result is not accceptable.

So, if there is a helper, I could not find it (or not use it properly).
1. With Mail().send, how to fill the 'message' parameter from a text field (let's say my_field) filled in via the ckeditor widget (which allows also to incluse a mail address or a URL).
2. After getting a response to this first question, if I want to append let's say 2 text fields, I 'm gonna try SPAN(my_first_text_field, BR(), my_second_text_field). Will this work?

Thanks in advance for any advice.

Richard Vézina

unread,
Jun 20, 2017, 3:53:14 PM6/20/17
to web2py-users
Hello Serge,

It not clear what you are doing exactly, do you mean you parse text with BeautifulSoup before input it into the database field? And what is unacceptable?

About 1, I think previous question would help understand better the issue.

About 2, I don't see why it wouldn't work... But as I am not sure what you try to accomplish, I mean if you strip off tag with beatiful in the first place why add some tag back when you send the message...

I am sure we would benefit to see a bit of your code to bettter help you.

Note that HTML in email is a difficult topic as render engine are much less homogeneous in email client like outlook, thunderbird than what you may have from a normal browser. So having the right presentation everywhere is more difficult to achieve than a regular web page.

Good Luck

Richard

--
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 the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Serge Bourgeois

unread,
Jun 21, 2017, 1:54:03 AM6/21/17
to web2py-users
Hello Richards,
Thanks for reading my question.

I'll try to clarify what I do and what I need.

I have a table with a text field. Using a SQLFORM.smartgrid, I use the ckeditor widget to populate this field, in order to get the data presented in a nice format (including for titles, email adresses, and so on).
This works fine.

Now, I want to generate an email with the content of this text field preserving the format created by the ckeditor widget.
I can make and send a mail (including with attachments), BUT:

When I open my mail, for instance with Firefox Web Browser, I see the tags used to format the text such as <p> </p>. My text is not formated as expected, and I see a series of special characters around email addresses or any url.

I found a way to suppress the tags and special chararcters using BeautifullSoup.BeautifullSoup, but then the result (what I read in Firefox Web Browser) looks like a long word (everything is concatenated, the url links are lost,. Therefore I say this is not acceptable).

I couldn't find a solution to get retrieve my formated text in Firefox Web Browser using the gluon Mail function. This is what I need.

As I am far from being an IT expert, I guess I missed or misunderstood something.

Serge
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

Serge Bourgeois

unread,
Jun 21, 2017, 2:08:47 AM6/21/17
to web2py-users
mailcode

Serge Bourgeois

unread,
Jun 21, 2017, 8:44:15 AM6/21/17
to web2py
Finally, I could find the solution to my first question. It is in fact very esay.

Here is my receipe:

Assuming that the content of the text field is in your local variable my_text_field_content, simply put this in the 'message' variable of the MAIL() function from gluon.tools:

message = (my_text_field_content, '<html>' + my_text_field_content + '</html>')

All  the other variables must of course been filled in as usual.

Hoping this can help some members of the community,

Serge

--
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/c1l7rXcJtJ8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

Richard Vézina

unread,
Jun 21, 2017, 10:14:17 AM6/21/17
to web2py-users
Hello Serge,

Yes, I guess your record is consider text so it is quoted... You seems to have find a solution, but you may have a look at XML() it gonna manage escaping and encoding for you... About the other field, if you keep going with you "manual" html tag (without using the web2py helpers) you better stick to it since you already have html formatted text content.

You mention firefox, why's that if you send mail?? Are you just send a link by mail to a user for him to access your content from you web site??

Good Luck

Richard

You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages