Ok, I solved it. The trick is that message is first text, then html. So the
signature should read like this:
context = dict(x=y)
message = response.render("message.html", context)
***Please note that the message.html file should be in the top level of
your views folder or should be a absolute path to it.
mail.send(to=[recipient],subject='subject',message=message)
will result in a text message.
to render as html, is :
mail.send(to=[recipient],subject='subject',message=[None,message])
On Sunday, September 23, 2012 8:05:24 PM UTC+1, Pystar wrote:
>
> Using this method, the mail is sent successfully,but shows raw html code
> in the email client, i.e. its not rendering
>
>
> On Friday, September 7, 2012 4:19:45 PM UTC+1, Niphlod wrote:
>>
>> it's a path relative to the app's *views *folder. With this code your *
>> message.html* should be next to layout.html, just in the
>> *yourapp/views/*folder.
>>
>> Il giorno venerdì 7 settembre 2012 17:04:27 UTC+2, Daniel Gonzalez ha
>> scritto:
>>>
>>> As explained here:
>>>
>>>
>>> http://web2py.com/books/default/chapter/29/8#Using-the-template-system-to-generate-messages
>>>
>>> The following code can be used to render a view file to send via email:
>>>
>>> for person in db(db.person).select():
>>> context = dict(person=person)
>>> message = response.render('message.html', context)
>>> mail.send(to=['[email protected]'],
>>> subject='None',
>>> message=message)
>>>
>>> I have tried this, but I am not able to place the "message.html"
>>> correctly in the directory hierarchy.
>>> How does reponse.render find the view files, or, even better, how can I
>>> tell response.render where to find my template file?
>>>
>>> Thanks,
>>> Daniel
>>>
>>
--