Procházet zdrojové kódy

中文乱码处理

xda před 3 roky
rodič
revize
53f4a4e13d

+ 3 - 0
.gitignore

@@ -12,3 +12,6 @@
 # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
 hs_err_pid*
 
+
+
+/target

+ 2 - 1
src/main/java/com/xxl/job/admin/core/alarm/impl/EmailJobAlarm.java

@@ -13,6 +13,7 @@ import org.springframework.mail.javamail.MimeMessageHelper;
 import org.springframework.stereotype.Component;
 
 import javax.mail.internet.MimeMessage;
+import java.nio.charset.StandardCharsets;
 import java.text.MessageFormat;
 import java.util.Arrays;
 import java.util.HashSet;
@@ -64,7 +65,7 @@ public class EmailJobAlarm implements JobAlarm {
                 try {
                     MimeMessage mimeMessage = XxlJobAdminConfig.getAdminConfig().getMailSender().createMimeMessage();
 
-                    MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
+                    MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, StandardCharsets.UTF_8.name());
                     helper.setFrom(XxlJobAdminConfig.getAdminConfig().getEmailFrom(), personal);
                     helper.setTo(email);
                     helper.setSubject(title);

+ 49 - 0
src/main/java/com/xxl/job/admin/core/conf/MailConfiguration.java

@@ -0,0 +1,49 @@
+package com.xxl.job.admin.core.conf;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.mail.javamail.JavaMailSenderImpl;
+
+import java.util.Properties;
+
+/**
+ * @Description: MailConfiguration
+ * @Author: xda
+ * @Date: 2021/7/23 14:13
+ */
+@Configuration
+public class MailConfiguration {
+
+    @Value("${spring.mail.host}")
+    private String host;
+
+    @Value("${spring.mail.port}")
+    private int port;
+
+    @Value("${spring.mail.username}")
+    private String username;
+
+    @Value("${spring.mail.password}")
+    private String password;
+
+    @Bean
+    public JavaMailSenderImpl javaMailSender() {
+        Properties properties = new Properties();
+        properties.setProperty("mail.smtp.auth", "true");
+        properties.setProperty("mail.smtp.starttls.enable", "true");
+        properties.setProperty("mail.smtp.starttls.required", "true");
+        properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
+
+        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
+        mailSender.setHost(host);
+        mailSender.setUsername(username);
+        mailSender.setPassword(password);
+        mailSender.setPort(port);
+        mailSender.setJavaMailProperties(properties);
+        return mailSender;
+
+    }
+
+
+}