开发者

Arabic is displayed as ????? in velocity template

开发者 https://www.devze.com 2023-01-28 04:35 出处:网络
Greetings all i am using velocity templates in sending emails and in the template i have some arabic texts

Greetings all i am using velocity templates in sending emails and in the template i have some arabic texts

and when sending the email, the text appears like ?????????? i don't know why:

encoding is set to utf-8 before sending the email here:

VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,templateName, "UTF-8",newModel);

i tried to add the charset in the vm, but with no luck:

<meta http-equiv="开发者_Python百科Content-Type" content="text/html; charset=UTF-8" />

any ideas why such problem occurs ?


I was able to produce Arabic text (تجاوز سعة مكدس) on a plain-text email sent from a Spring app. The text displayed properly on GMail as well as Thunderbird. Here's my mail sending logic:

public void send(String fromAddress, String fromName,
    String toAddress, String subject,
    String template, Map<String, Object> model) {
  MimeMessagePreparator preparator = new MimeMessagePreparator() {
    public void prepare(MimeMessage mimeMessage) throws Exception {
      MimeMessageHelper message = new MimeMessageHelper(
          mimeMessage, "UTF-8");
      message.setTo(toAddress);
      message.setFrom(new InternetAddress(fromAddress, fromName));
      message.setSubject(subject);
      message.setText(VelocityEngineUtils
          .mergeTemplateIntoString(velocityEngine, template, "UTF-8", 
              model));
    }
  };
  mailSender.send(preparator);
}


Do you have any velocity.properties set? (particularly input.encoding or output.encoding) If not, try setting those both to UTF-8 also.

0

精彩评论

暂无评论...
验证码 换一张
取 消