Forum OpenACS Development: Re: html in emails.

Collapse
8: Re: html in emails. (response to 1)
Posted by Richard Hamilton on
Please accept my apologies as I gradually ascend the learning curve. Please disregard the previously proposed ugly hack!

This post is aimed at the non expert - experts please smile smugly!

ns_sendmail can receive additional email header declarations which can be passed when the proc is called. The variable that receives the header that you want to pass is called 'extraheaders' in ns_sendmail and the functionality is implemented using an aolserver tcl api call - ns_set.

To specify a single part html email you need to use ns_set in the calling procedure to set a (or multiple) key-value pair(s) to contain the appropriate header(s), and then pass the set to ns_sendmail by adding the name of your new key-value pair set to the list of parameters to be passed. ns_sendmail will then add the header to the email in the appropriate way and everyone will live happily ever after. Example below specifies that the email is html and will satisfy the dreaded MS Outlook.

set extraheaders [ns_set create headers]
ns_set put $extraheaders "Content-Type" "test/html;"


Then call ns_sendmail in the usual way wrapped in a 'catch' :

if [catch {ns_sendmail $email $system_owner $subject $body $extraheaders} errmsg] {
etc.....


Regards
Richard
Collapse
9: Re: html in emails. (response to 8)
Posted by Alfred Werner on
just noticed this -

in the example - it should NOT be

ns_set put $extraheaders "Content-Type" "test/html;"

but rather

ns_set put $extraheaders "Content-Type" "text/html;"

i.e. not TEST, but TEXT