im fighting with strange error. Im using seperate freemarker templates for mail subject and body. It is sent using org.springframework.mail.javamail.JavaMailSender. Only templates that contains some special swedish character works in my application ( yes you read right… not the other way). If I delete it my email content crashes. It contains then:
MIME-Version: 1.0
Content-Type: text/html;charset=UTF-8
Content-Transfer-Encoding: 7bit
..
html code here
..
My freemarker.properties file
locale=sv_SE
classic_compatible=false
number_format=
date_format=yyyy-MM-dd
time_format=HH:mm
datetime_format=yyyy-MM-dd HH:mm
output_encoding=UTF-8
url_escaping_charset=UTF-8
auto_import=spring.ftl as spring
auto_include=
default_encoding=UTF-8
localized_lookup=true
strict_syntax=true
whitespace_stripping=true
template_update_delay=10
Ive tried to convert subject file with dos2unix tool. Using ‘find -bi subject.ftl’ show that encoding is us-ascii. With added special character – utf-8.
This thing is suprisingly strange for me…
//SOLUTION:
use :set bomb and save file in vim.
As per request of @freakman, I post my comment as an answer – as it turned out to solve the problem:
Append the BOM (Byte Order Mark) to the beginning of the template file, to ensure it is always parsed as an UTF-8 template.
For reference, the BOM for UTF-8 is:
EF BB BFbyte[] bom = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF};