I am using Spring Message with placeholders to create an email message. The arguments for the placeholders contain International Characters. Once the email body text is set using the getMessage()
method with message, arguments and Locale and email is sent, the email received has the placeholder values with ISO-8859 chars. How to ensure that the UTF-8 encoded Arguments are preserved while getting replaced in the message property.
Return property bundle:
@Bean
public MessageSource emailProps() {
ReloadableResourceBundleMessageSource messageSource = new
ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath:props/Email");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
MailSender.java
@Autowired
private MessageSource emailProps;
public void send(String to, String language,String name, String org_name) throws MessagingException {
//org_name has values like "GmbH (Süd) München"
//some code here
MimeMessage message = javaMailSender.createMimeMessage();
MimeMessageHelper helper=new MimeMessageHelper(message,
MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED, "UTF-8");
//helper.setFrom, helper.setTo....
helper.setText(emailProps.getMessage("security.email.body", new Object[] {name,org_name},
Locale.GERMAN)+emailProps.getMessage("email.footer", null, Locale.GERMAN), true);
//remaining part of the code
}
In the Email org_name comes up as "GmbH (Süd) München".
Question: What should I do so that the UTF-8 encoded argument values are retained as-is? I have the argument values coming from DB and have verified that they do retain the encoding till the step before they are written into the message body.