我正在尝试使用
spring-boot-starter-thymeleaf
spring-boot-starter-mail 2.0.1
spring-boot 2.0.5
发送电子邮件,但我收到问号而不是带重音符号的字母
我尝试了很多事情,但不明白为什么我会得到-而是带有重音符号的字符。
示例 合法的有效条款 有效的选民条款
我的配置:
@Configuration
public class AppConfig {
@Bean
@Description("Thymeleaf template resolver serving HTML 5")
public ClassLoaderTemplateResolver templateResolver() {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("/ressources/templates/");
templateResolver.setCacheable(false);
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML5");
templateResolver.setCharacterEncoding("UTF-8");
return templateResolver;
}
}
我的内容生成器
@Autowired
public MailContentBuilder(TemplateEngine templateEngine) {
this.templateEngine = templateEngine;
}
public String build(String message,String tempName) {
Context context = new Context();
context.setVariable("environment", env);
context.setVariable("message", message);
return templateEngine.process(tempName, context);
}
我的application.properties:
spring.mail.host: host
spring.mail.port: 465
spring.mail.username: user
spring.mail.password: pwd
spring.mail.properties.mail.smtp.auth: true
spring.mail.properties.mail.smtp.starttls.enable: true
spring.mail.properties.mail.smtp.starttls.required: true
spring.mail.properties.mail.smtp.ssl.enable: true
spring.mail.test-connection: false
spring.mail.properties.mail.smtp.ssl.trust=smtp.domain.com
我的HTML模板:
<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html lang="fr" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="utf-8">
</head>
<body>
<div>
Votre article vient d'être validée pour être mise en ligne<br>
</div>
</body>
</html>
我尝试过: utf8 charset with Thymeleaf
,SpringBoot - UTF-8 Doesnt work in messages.properties
和How to set UTF-8 character encoding in Spring boot?
但仍然存在相同的问题