It looks like you are doing everything correctly in the examples you gave below.
So to help us track down if this is a bug could you please include your full email template as a text file.
We will hopefully then be able to track down where or why the failure is happening and submit a bug fix at that point.
This was the exact line we were using. We just found out about the templates so we have not been using them heavily. I also tried this with both text and html emails and neither seemed to work.
After doing some testing, I am seeing that issue if the code is placed in the subject of the email, is that where you are placing the code?
Unfortunately the email subject is not parsed in the same way as the email body, you will find if you put the same code in the body it will work as intended.