VelocityEngineUtils.mergeTemplateIntoString encoding to use when creating email

With Spring 3.0.5, I can create emails by calling VelocityEngineUtils.mergeTemplateIntoString(VelocityEngine velocityEngine, String templateLocation, Map model) . This method generates a string that is fully compatible with MIME mail.

Since Spring 3.2.11 this method is not supported: you need to use VelocityEngineUtils.mergeTemplate(VelocityEngine velocityEngine, String templateLocation, String encoding, Map model, Writer writer) with the optional encoding parameter.

Being a mail context, I tried org.apache.commons.codec.CharEncoding.US_ASCII (which is equal to US-ASCII ), but it completely breaks my letters. All the clients I tried (Outlook Web Mail, Outlook 2013, Windows 8 Mail) do not see the themes and do not display all parts of MIME, as shown below:

 ------=_Part_0_1846461141.1413184892265 Content-Type: multipart/related; boundary="----=_Part_1_249771572.1413184892276" ------=_Part_1_249771572.1413184892276 Content-Type: multipart/alternative; boundary="----=_Part_2_861087694.1413184892311" ------=_Part_2_861087694.1413184892311 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 

(Look at UTF-8!)

Question: what is the correct way to call mergeTemplateIntoString with an encoding argument?

+5
source share

Source: https://habr.com/ru/post/1204545/


All Articles