Reputation: 991
I am sending email using velocity template in Rusian language, the mail receiving with junk character.
The mail template.
<html>
<body>
<h3>Dear ${name},
<br/>Greetings from ${companyName}.</h3>
<span>Your Subscription will expire on : ${expiryDate}</span><br/>
<span>Нажмите <a href=${homePageUrl}>здесь</a>, чтобы войти.</span><br/>
<span>Click <a href=${homePageUrl}>here</a> to login.</span><br/>
<h3>Regards, <br/>
${companyName}</h3>
</body>
</html>
The receiving mail:-
Dear Deepesh, Greetings from ..... Your Subscription will expire on : 23-04-2029 Ru ??????? ?????, ????? ?????. Click here to login. Regards, Budbeed Learning
The Russian part is junk.
Now my email send code.
SendEmailResponse response = null;
try {
VelocityContext velocityContext = new VelocityContext();
final Map<String, String> contextMap = request.getContextMap();
for(Map.Entry<String,String> entry : contextMap.entrySet()) {
velocityContext.put(entry.getKey(), entry.getValue());
}
StringWriter stringWriter = new StringWriter();
velocityEngine.mergeTemplate("/templates/" + contextMap.get("templateName"),"UTF-8", velocityContext, stringWriter);
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
mimeMessageHelper.setFrom(KP_DEV_MAIL_RU);
mimeMessageHelper.setTo(contextMap.get("email"));
mimeMessageHelper.setSubject(contextMap.get("subject"));
mimeMessageHelper.setText(stringWriter.toString(), true);
/*FileSystemResource file = new FileSystemResource(new File("banner.jpg"));
mimeMessageHelper.addInline("banner", file);
FileSystemResource fileSystemResource = new FileSystemResource(new File("Attachment.jpg"));
mimeMessageHelper.addAttachment("Attachment.jpg", fileSystemResource);*/
InputStreamSource source = new ByteArrayResource(request.getFile().toByteArray());
mimeMessageHelper.addAttachment("Invoice.pdf", source );
if(LMSCommonUtils.matchEmail(contextMap.get("email"))) {
javaMailSender.send(mimeMessage);
}
}catch (Exception e) {
LOGGER.error("Error while sending invoice",e);
res
}
Upvotes: 0
Views: 1267
Reputation: 4509
I believe javamailsender also should configure UTF8
. Try like below
javaMailSender.setDefaultEncoding("UTF-8");
Upvotes: 1