Добрый день. Возникла проблема с кодировкой при отправке почты.
private void sendEmail(String from, String to, String subject, String text, boolean isHtml) {
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, "utf-8");
helper.setFrom(from);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(text, isHtml);
javaMailSender.send(mimeMessage);
} catch (MessagingException e) {
LOG.error("message send error", e);
}
}
<bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.yandex.ru"/>
<property name="port" value="465"/>
<property name="protocol" value="smtp"/>
<property name="username" value="****"/>
<property name="password" value="****"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">false</prop>
<prop key="mail.smtp.quitwait">false</prop>
<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
<prop key="mail.smtp.socketFactory.fallback">false</prop>
<prop key="mail.debug">true</prop>
</props>
</property>
</bean>
Лог:
250 /127.0.0.1
DEBUG SMTP: use8bit false
MAIL FROM:<****@yandex.ru>
250 OK
RCPT TO:<****@gmail.com>
250 OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP: ****@gmail.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Date: Sun, 28 Feb 2016 13:27:49 +0300 (MSK)
From: ****@yandex.ru
To: ****@gmail.com
Message-ID: <1629378585.0.1456655269089.JavaMail.hobbit@laptop>
Subject: Feedback
MIME-Version: 1.0
Content-Type: text/html;charset=utf-8
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html>
<html xmlns=3D"http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DU=
TF-8"/>
</head>
<body>
<p>=D0=A1=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B5 =D0=BE=D1=
=82 Mike</p>
<p>Hi!</p>
<p>=D0=94=D0=BB=D1=8F =D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=B0 =D0=BE=
=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D1=8C=D1=82=D0=B5 =D1=81=D0=BE=D0=BE=D0=B1=
=D1=89=D0=B5=D0=BD=D0=B8=D0=B5 =D0=BD=D0=B0 ****@gmail.com</p>
</body>
</html>
.
250 OK
QUIT
Пробовал, что советуют в google(не помогает, кодировка бьется в момент отправки):
System.setProperty("mail.mime.charset", "utf-8");
mimeMessage.setContent(message, "text/html; charset=utf-8");
<property name="defaultEncoding" value="utf-8"/>