I am sending emails with the Spring MimeMessageHelper, which uses the JavaMail API in the background. I would like to have an option to input the recipient's name like this:
private static void setTo(final EmailDTO emailDTO, MimeMessageHelper helper) throws MessagingException {
if (StringUtils.isBlank(emailDTO.getToName())) {
helper.setTo(emailDTO.getToEmail());
} else {
helper.setTo(emailDTO.getToName() + " <" + emailDTO.getToEmail() + ">");
}
}
However, this throws a
javax.mail.internet.AddressException: Illegal character in address ( Őry József <mail@testcompany.com> )
..when there are accented characters in the name.Which function shall I use for encoding the name in this case?