Procházet zdrojové kódy

官网接口修改

wutt před 5 roky
rodič
revize
922b5e0425

+ 18 - 0
website/pom.xml

@@ -22,6 +22,18 @@
         <thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
 
     </properties>
+    <repositories>
+        <repository>
+            <id>alimaven</id>
+            <name>aliyun maven</name>
+            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
+        </repository>
+        <repository>
+            <id>alimaven2</id>
+            <name>aliyun maven 2</name>
+            <url>http://maven.aliyun.com/nexus/content/repositories/central</url>
+        </repository>
+    </repositories>
 
     <dependencies>
         <dependency>
@@ -76,6 +88,12 @@
             <artifactId>mysql-connector-java</artifactId>
             <scope>runtime</scope>
         </dependency>
+        <!--发送邮件的依赖-->
+        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-mail</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>

+ 68 - 0
website/src/main/java/com/hssx/website/config/MailConfiguration.java

@@ -0,0 +1,68 @@
+package com.hssx.website.config;
+import	java.util.Properties;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.mail.javamail.JavaMailSenderImpl;
+
+//实例化JavaMailSenderImpl并把它加入到IOC容器
+@Configuration
+public class MailConfiguration {
+    @Value("${spring.mail.host}")
+    private String host;
+    @Value("${spring.mail.password}")
+    private String password;
+    @Value("${spring.mail.default-encoding}")
+    private String encoding;
+    @Value("${spring.mail.username}")
+    private String username;
+    @Value("${spring.mail.properties.mail.smtp.auth}")
+    private String smtpAuth;
+    @Value("${spring.mail.properties.mail.smtp.starttls.enable}")
+    private String starttlsEnable;
+    @Value("${spring.mail.properties.mail.smtp.starttls.required}")
+    private String starttlsRequired;
+    @Value("${spring.mail.port}")
+    private Integer port;
+    @Value("${spring.mail.properties.mail.smtp.socketFactory.port}")
+    private String socketFactoryPort;
+    @Value("${spring.mail.properties.mail.smtp.socketFactory.class}")
+    private String socketFactoryClass;
+    @Value("${spring.mail.properties.mail.smtp.socketFactory.fallback}")
+    private String socketFactoryFallback;
+
+    @Bean("mailSender")
+    public JavaMailSenderImpl JavaMailSender(){
+        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
+        mailSender.setHost(host);
+        mailSender.setUsername(username);
+        mailSender.setPassword(password);
+        mailSender.setDefaultEncoding(encoding);
+        mailSender.setPort(port);
+        Properties properties = new Properties();
+        properties.setProperty("mail.smtp.ssl.enable",starttlsEnable);
+        properties.setProperty("mail.smtp.auth",smtpAuth);
+        properties.setProperty("mail.smtp.ssl.required",starttlsRequired);
+        properties.setProperty("mail.smtp.socketFactory.port",socketFactoryPort);
+        properties.setProperty("mail.smtp.socketFactory.class",socketFactoryClass);
+        properties.setProperty("mail.smtp.socketFactory.fallback",socketFactoryFallback);
+        mailSender.setJavaMailProperties(properties);
+        return  mailSender;
+    }
+    //163的邮箱
+//    @Bean("mailSender")
+//    public JavaMailSenderImpl JavaMailSender(){
+//        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
+//        mailSender.setHost("14.18.245.164");
+//        mailSender.setUsername("1160233059@qq.com");
+//        mailSender.setPassword("crqjmnieqsdsjgcd");
+//        mailSender.setDefaultEncoding("UTF-8");
+//        mailSender.setPort(465);
+//        Properties properties = new Properties();
+//        properties.setProperty("mail.smtp.ssl.enable","true");
+//        mailSender.setJavaMailProperties(properties);
+//        return  mailSender;
+//    }
+}

+ 3 - 4
website/src/main/java/com/hssx/website/controller/ArticleController.java

@@ -12,6 +12,8 @@ import com.hssx.website.until.HttpRespMsg;
 import com.hssx.website.until.PageUtil;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.PropertySource;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -35,7 +37,6 @@ public class ArticleController {
     private CommentService commentService;
     @Autowired
     private OnlineApplicationService onlineApplicationService;
-
     @ApiOperation("案例")
     @GetMapping("/index")
     public String index(Model model) {
@@ -62,9 +63,7 @@ public class ArticleController {
     @PostMapping("/add")
     @ResponseBody
     public HttpRespMsg addComment(Comment comment) {
-        HttpRespMsg msg = new HttpRespMsg();
-        msg.data = commentService.save(comment);
-        return msg;
+        return commentService.saveCommit(comment);
     }
     @ApiOperation("在线申请")
     @PostMapping("/onlineApply")

+ 2 - 0
website/src/main/java/com/hssx/website/service/CommentService.java

@@ -2,6 +2,7 @@ package com.hssx.website.service;
 
 import com.hssx.website.entity.Comment;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.hssx.website.until.HttpRespMsg;
 
 /**
  * <p>
@@ -13,4 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface CommentService extends IService<Comment> {
 
+    HttpRespMsg saveCommit(Comment comment);
 }

+ 38 - 0
website/src/main/java/com/hssx/website/service/IMailService.java

@@ -0,0 +1,38 @@
+package com.hssx.website.service;
+
+/**
+ * @Author: 吴涛涛
+ * @Description: 封装一个发邮件的接口,后边直接调用即可
+ * @Date: Create in 2019/1/28/0028 21:57
+ * @param: $params$
+ * @return: $returns$
+ */
+public interface IMailService {
+
+    /**
+     * 发送文本邮件
+     * @param to 收件人
+     * @param subject 主题
+     * @param content 内容
+     */
+    void sendSimpleMail(String to, String subject, String content);
+
+    /**
+     * 发送HTML邮件
+     * @param to 收件人
+     * @param subject 主题
+     * @param content 内容
+     */
+    public void sendHtmlMail(String to, String subject, String content);
+
+
+
+    /**
+     * 发送带附件的邮件
+     * @param to 收件人
+     * @param subject 主题
+     * @param content 内容
+     * @param filePath 附件
+     */
+    public void sendAttachmentsMail(String to, String subject, String content, String filePath);
+}

+ 0 - 4
website/src/main/java/com/hssx/website/service/OnlineApplicationService.java

@@ -6,10 +6,6 @@ import com.hssx.website.until.HttpRespMsg;
 import com.hssx.website.until.PageUtil;
 
 /**
- * <p>
- *  服务类
- * </p>
- *
  * @author 吴涛涛
  * @since 2019-11-21
  */

+ 58 - 0
website/src/main/java/com/hssx/website/service/impl/CommentServiceImpl.java

@@ -1,11 +1,20 @@
 package com.hssx.website.service.impl;
 
+import java.lang.ref.Reference;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
 import com.hssx.website.entity.Comment;
 import com.hssx.website.mapper.CommentMapper;
 import com.hssx.website.service.CommentService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.hssx.website.service.IMailService;
+import com.hssx.website.until.HttpRespMsg;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+
 /**
  * <p>
  * the comments left by customers 服务实现类
@@ -17,4 +26,53 @@ import org.springframework.stereotype.Service;
 @Service
 public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
 
+    @Resource
+    private CommentMapper commentMapper;
+    @Resource
+    private IMailService iMailService;
+    @Value("${sendMailbox}")
+    private String sendMailbox;
+    @Value("${mailSubject}")
+    private String mailSubject;
+
+
+    @Override
+    public HttpRespMsg saveCommit(Comment comment) {
+        commentMapper.insert(comment);
+        String text = "<!DOCTYPE html>"
+                + "<html lang='en'>"
+                + "<head>"
+                + "<meta charset='UTF-8'>"
+                + "<title>邮件提醒</title>"
+                + "<meta name='viewport' content='width=device-width, initial-scale=1.0'/>"
+                + "</head>"
+                + "<body style=margin: 0; padding: 0;>"
+                + "<table align='center' border='0' cellpadding='0' cellspacing='0' width='600' style='border-collapse: collapse;'>"
+                + "<tr>"
+                + "<td>"
+                + "<div style='margin: 40px;text-align: center;margin-top: 50px;border-bottom:1px solid gray;padding:20px'>"
+                + "</div>"
+                + "</td>"
+                + "</tr>"
+                + "<tr>"
+                + "<td>"
+                + "<div style='margin: 40px'>"
+                + "<p style='font-size: 16px'>" + comment.getComment() + "</p>"
+                + "</div>"
+                + "</td>"
+                + "</tr>"
+                + "<tr>"
+                + "<td>"
+                + "<div align='right' style='margin: 40px;border-top: solid 1px gray' id='bottomTime'>"
+                + "<p style='margin-right: 20px'>留言人:  " + comment.getName() + "</p>"
+                + "<p style='margin-right: 20px'>电话:  " + comment.getPhone() + "</p>"
+                + "<label style='margin-right: 20px'>留言日期:  " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "</label>"
+                + "</div>"
+                + "</td>"
+                + "</tr>"
+                + "</table>"
+                + "</body>";
+        iMailService.sendSimpleMail(sendMailbox, mailSubject, text);
+        return new HttpRespMsg();
+    }
 }

+ 128 - 0
website/src/main/java/com/hssx/website/service/impl/IMailServiceImpl.java

@@ -0,0 +1,128 @@
+package com.hssx.website.service.impl;
+
+import com.hssx.website.service.IMailService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.mail.SimpleMailMessage;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.JavaMailSenderImpl;
+import org.springframework.mail.javamail.MimeMessageHelper;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import java.io.File;
+
+/**
+ * @Author: 吴涛涛
+ * @Description:
+ * @Date: Create in 2019/1/28/0028 22:00
+ * @param: $params$
+ * @return: $returns$
+ */
+@Service("iMailService")
+public class IMailServiceImpl implements IMailService {
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    /**
+     * Spring Boot 提供了一个发送邮件的简单抽象,使用的是下面这个接口,这里直接注入即可使用
+     */
+    @Resource
+    private JavaMailSenderImpl mailSender;
+
+    /**
+     * 配置文件中我的邮箱
+     */
+    @Value("${spring.mail.username}")
+    private String from;
+
+    /**
+     * 简单文本邮件
+     * @param to 收件人
+     * @param subject 主题
+     * @param content 内容
+     */
+    @Override
+    public void sendSimpleMail(String to, String subject, String content) {
+        //创建SimpleMailMessage对象
+        SimpleMailMessage message = new SimpleMailMessage();
+        //邮件发送人
+        message.setFrom(from);
+        //邮件接收人
+        message.setTo(to);
+        //邮件主题
+        message.setSubject(subject);
+        //邮件内容
+        message.setText(content);
+        //发送邮件
+        mailSender.send(message);
+        logger.info("邮件已经发送。");
+    }
+
+    /**
+     * html邮件
+     * @param to 收件人
+     * @param subject 主题
+     * @param content 内容
+     */
+    @Override
+    public void sendHtmlMail(String to, String subject, String content) {
+        //获取MimeMessage对象
+        MimeMessage message = mailSender.createMimeMessage();
+        MimeMessageHelper messageHelper;
+        try {
+            messageHelper = new MimeMessageHelper(message, true);
+            //邮件发送人
+            messageHelper.setFrom(from);
+            //邮件接收人
+            messageHelper.setTo(to);
+            //邮件主题
+            message.setSubject(subject);
+            //邮件内容,html格式
+            messageHelper.setText(content, true);
+            //发送
+            mailSender.send(message);
+            //日志信息
+            logger.info("邮件已经发送。");
+        } catch (MessagingException e) {
+            logger.error("发送邮件时发生异常!", e);
+        }
+    }
+
+    /**
+     * 带附件的邮件
+     * @param to 收件人
+     * @param subject 主题
+     * @param content 内容
+     * @param filePath 附件
+     */
+    @Override
+    public void sendAttachmentsMail(String to, String subject, String content, String filePath) {
+        MimeMessage message = mailSender.createMimeMessage();
+        try {
+            MimeMessageHelper helper = new MimeMessageHelper(message, true);
+            helper.setFrom(from);
+            helper.setTo(to);
+            helper.setSubject(subject);
+            helper.setText(content, true);
+
+            FileSystemResource file = new FileSystemResource(new File(filePath));
+            String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
+            helper.addAttachment(fileName, file);
+            mailSender.send(message);
+            //日志信息
+            logger.info("邮件已经发送。");
+        } catch (MessagingException e) {
+            logger.error("发送邮件时发生异常!", e);
+        }
+
+
+    }
+}

+ 39 - 0
website/src/main/resources/application-prod.properties

@@ -62,4 +62,43 @@ spring.datasource.hikari.connection-test-query=SELECT 1
 ########################################################################################################
 # 日志
 logging.path=E:/staticproject/cloudmodel/
+###################
+## QQ邮箱配置
+# 发送到的邮箱
+sendMailbox=976575821@qq.com
+# 邮件标题
+mailSubject=新留言通知
+spring.mail.host=14.18.245.164
+spring.mail.username=1160233059@qq.com
+#客户端授权码去设置里获取
+spring.mail.password=crqjmnieqsdsjgcd
+spring.mail.default-encoding=UTF-8
+spring.mail.properties.mail.smtp.auth=true
+spring.mail.properties.mail.smtp.starttls.enable=true
+spring.mail.properties.mail.smtp.starttls.required=true
+# 端口号465或587
+spring.mail.port=465
+# 端口号465或587
+spring.mail.properties.mail.smtp.socketFactory.port = 465
+spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
+spring.mail.properties.mail.smtp.socketFactory.fallback = false
+## 163邮箱配置
+# 发送到的邮箱
+#sendMailbox=18130408125@163.com
+## 邮件标题
+#mailSubject=新留言通知
+#spring.mail.host=220.181.12.13
+#spring.mail.username=18130408125@163.com
+##客户端授权码
+#spring.mail.password=wtt102345
+##编码方式
+#spring.mail.default-encoding=UTF-8
+#spring.mail.properties.mail.smtp.auth=true
+#spring.mail.properties.mail.smtp.starttls.enable=true
+#spring.mail.properties.mail.smtp.starttls.required=true
+##端口994或者465
+#spring.mail.port=994
+#spring.mail.properties.mail.smtp.socketFactory.port = 994
+#spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
+#spring.mail.properties.mail.smtp.socketFactory.fallback = false
 

+ 30 - 0
website/src/main/resources/application-prod.yml

@@ -29,4 +29,34 @@ mybatis-plus:
     cache-enabled: false
 ########################
 
+      ###########################################
+      ## QQ邮箱配置
+#      spring:
+#        mail:
+#          host: smtp.qq.com #发送邮件服务器
+#          username: 1160233059@qq.com #发送邮件的邮箱地址
+#          password:  ivhkrc*****kbdcf #客户端授权码,不是邮箱密码,这个在qq邮箱设置里面自动生成的
+#          properties.mail.smtp.port: 465 #端口号465或587
+#          from: 1160233059@qq.com # 发送邮件的地址,和上面username一致
+#        #可以任意
+#        properties.mail.smtp.starttls.enable: true
+#        properties.mail.smtp.starttls.required: true
+#        properties.mail.smtp.ssl.enable: true
+#        default-encoding: utf-8
+
+
+#         ##网易系(126/163/yeah)邮箱配置
+#         spring:
+#           mail:
+#             host: smtp.126.com #发送邮件服务器
+#             username: xx@126.com #发送邮件的邮箱地址
+#             password: xxxxxxx #客户端授权码,不是邮箱密码,网易的是自己设置的
+#             properties.mail.smtp.port: 994 #465或者994
+#             from: xxx@126.com # 发送邮件的地址,和上面username一致
+#             可以任意
+#             properties.mail.smtp.starttls.enable: true
+#             properties.mail.smtp.starttls.required: true
+#             properties.mail.smtp.ssl.enable: true
+#             default-encoding: utf-8
+
 

+ 41 - 0
website/src/main/resources/application.properties

@@ -66,4 +66,45 @@ spring.datasource.hikari.connection-test-query=SELECT 1
 logging.path=E:/
 
 
+## QQ邮箱配置
+# 发送到的邮箱
+sendMailbox=976575821@qq.com
+# 邮件标题
+mailSubject=新留言通知
+spring.mail.host=14.18.245.164
+spring.mail.username=1160233059@qq.com
+#客户端授权码去设置里获取
+spring.mail.password=crqjmnieqsdsjgcd
+spring.mail.default-encoding=UTF-8
+spring.mail.properties.mail.smtp.auth=true
+spring.mail.properties.mail.smtp.starttls.enable=true
+spring.mail.properties.mail.smtp.starttls.required=true
+# 端口号465或587
+spring.mail.port=465
+# 端口号465或587
+spring.mail.properties.mail.smtp.socketFactory.port = 465
+spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
+spring.mail.properties.mail.smtp.socketFactory.fallback = false
+## 163邮箱配置
+# 发送到的邮箱
+#sendMailbox=18130408125@163.com
+## 邮件标题
+#mailSubject=新留言通知
+#spring.mail.host=220.181.12.13
+#spring.mail.username=18130408125@163.com
+##客户端授权码
+#spring.mail.password=wtt102345
+##编码方式
+#spring.mail.default-encoding=UTF-8
+#spring.mail.properties.mail.smtp.auth=true
+#spring.mail.properties.mail.smtp.starttls.enable=true
+#spring.mail.properties.mail.smtp.starttls.required=true
+##端口994或者465
+#spring.mail.port=994
+#spring.mail.properties.mail.smtp.socketFactory.port = 994
+#spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
+#spring.mail.properties.mail.smtp.socketFactory.fallback = false
+
+
+
 

+ 2 - 0
website/src/main/resources/application.yml

@@ -37,3 +37,5 @@ mybatis-plus:
        content-type: text/html
        mode: HTML5
 
+ ###########################################
+

+ 36 - 0
website/src/main/resources/templates/sendTemp.html

@@ -0,0 +1,36 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html lang="en" xmlns:th="http://www.thymeleaf.org">
+	<head>
+		<meta charset="UTF-8">
+		<title>邮件提醒</title> 
+		<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+	</head>
+
+	<body style="margin: 0; padding: 0;">
+		<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="border-collapse: collapse;">   
+			<tr>
+				<td>
+					<div style="margin: 40px;text-align: center;margin-top: 50px;border-bottom:1px solid gray;padding:20px">
+						
+					</div>
+				</td>
+			</tr>
+			<tr>
+				<td>
+					<div style="margin: 40px">
+						<p style="font-size: 16px">内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容</p>
+					</div>
+				</td>
+			</tr>
+			<tr>
+				<td>
+					<div align="right" style="margin: 40px;border-top: solid 1px gray" id="bottomTime">
+						<p style="margin-right: 20px">周瑞霆</p>
+						<p style="margin-right: 20px">18255585207</p>
+						<label style="margin-right: 20px">2018年08月30日</label>
+					</div>
+				</td>
+			</tr>
+		</table>
+	</body>
+</html>

+ 131 - 2
website/src/test/java/com/hssx/website/WebsiteApplicationTests.java

@@ -1,13 +1,142 @@
 package com.hssx.website;
 
+import com.hssx.website.entity.Comment;
+import com.hssx.website.service.IMailService;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.mail.MailSender;
+import org.springframework.mail.SimpleMailMessage;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.JavaMailSenderImpl;
+import org.springframework.mail.javamail.MimeMessageHelper;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 @SpringBootTest
-class WebsiteApplicationTests {
+@RunWith(SpringRunner.class)
+public class WebsiteApplicationTests {
+
+    /**
+     * 注入发送邮件的接口
+     */
+    @Autowired
+    private IMailService mailService;
 
+    /**
+     * 测试发送文本邮件
+     */
     @Test
-    void contextLoads() {
+    public void sendmail() {
+//        mailService.sendSimpleMail("1069406348@qq.com","老弟给姐来邮件了","聪明伶俐、\n" +
+//                "\n" +
+//                "沉鱼落雁、\n" +
+//                "\n" +
+//                "闭月羞花、\n" +
+//                "\n" +
+//                "风华绝代、\n" +
+//                "\n" +
+//                "花容月貌、\n" +
+//                "\n" +
+//                "亭亭玉立、\n" +
+//                "\n" +
+//                "美如冠玉、\n" +
+//                "\n" +
+//                "眉目如画、\n" +
+//                "\n" +
+//                "风度翩翩、\n" +
+//                "\n" +
+//                "国色天香、\n" +
+//                "\n" +
+//                "倾国倾城、\n" +
+//                "\n" +
+//                "出水芙蓉、\n" +
+//                "\n" +
+//                "天生丽质、\n" +
+//                "\n" +
+//                "珠光宝气、\n" +
+//                "\n" +
+//                "明眸皓齿、\n" +
+//                "\n" +
+//                "冰肌玉骨、\n" +
+//                "\n" +
+//                "秀色可餐、\n" +
+//                "\n" +
+//                "金枝玉叶");
+//        mailService.sendSimpleMail("976575821@qq.com","主题:你好普通邮件","内容:第一封邮件");
+        Comment comment = new Comment();
+        comment.setComment("你好呀小伙子");
+        comment.setName("小猴");
+        comment.setPhone("123456789");
+        String text = "<!DOCTYPE html>"
+                + "<html lang='en'>"
+                + "<head>"
+                + "<meta charset='UTF-8'>"
+                + "<title>邮件提醒</title>"
+                + "<meta name='viewport' content='width=device-width, initial-scale=1.0'/>"
+                + "</head>"
+                + "<body style=margin: 0; padding: 0;>"
+                + "<table align='center' border='0' cellpadding='0' cellspacing='0' width='600' style='border-collapse: collapse;'>"
+                + "<tr>"
+                + "<td>"
+                + "<div style='margin: 40px;text-align: center;margin-top: 50px;border-bottom:1px solid gray;padding:20px'>"
+                + "</div>"
+                + "</td>"
+                + "</tr>"
+                + "<tr>"
+                + "<td>"
+                + "<div style='margin: 40px'>"
+                + "<p style='font-size: 16px'>" + comment.getComment() + "</p>"
+                + "</div>"
+                + "</td>"
+                + "</tr>"
+                + "<tr>"
+                + "<td>"
+                + "<div align='right' style='margin: 40px;border-top: solid 1px gray' id='bottomTime'>"
+                + "<p style='margin-right: 20px'>留言人:  " + comment.getName() + "</p>"
+                + "<p style='margin-right: 20px'>电话:  " + comment.getPhone() + "</p>"
+                + "<label style='margin-right: 20px'>留言日期:  " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "</label>"
+                + "</div>"
+                + "</td>"
+                + "</tr>"
+                + "</table>"
+                + "</body>";
+
+//        String text = "<html>\n"+"<body>\n"
+//                + "<h3>hello world!测试发送html格式邮件</h3>\n"
+//                +"</body>\n"+"</html>";
+//        mailService.sendHtmlMail("18130408125@163.com","新留言通知",text);
+        mailService.sendHtmlMail("18130408125@163.com","新留言通知",text);
+        System.out.println("发送成功");
     }
 
+//    @Test
+//    public void sendmailHtml(){
+//        mailService.sendHtmlMail("smfx1314@163.com","主题:你好html邮件","<h1>内容:第一封html邮件</h1>");
+//    }
+//    @Autowired
+//    JavaMailSender mailSender; //添加依赖后可以直接引用
+//
+//    public void sendMail(String emailForm,String[] emailTo,String title,String context){
+//        System.setProperty("java.net.preferIPv4Stack", "true");
+//        MimeMessage mimeMessage = mailSender.createMimeMessage();
+//        MimeMessageHelper helper;
+//        try {
+//            helper = new MimeMessageHelper(mimeMessage, true);
+//            helper.setFrom(emailForm);
+//            helper.setTo(emailTo);
+//            helper.setSubject(title);//主题
+//            helper.setText(context);//正文
+//            mailSender.send(mimeMessage);
+//        } catch (MessagingException e1) {
+//            // TODO Auto-generated catch block
+//            e1.printStackTrace();
+//        }
+//    }
+
 }