liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.tools.web;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
 
import com.jeeplus.common.mail.MailSendUtils;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.sys.entity.SystemConfig;
import com.jeeplus.modules.sys.service.SystemConfigService;
 
/**
 * 发送外部邮件
 * @author lgf
 * @version 2016-01-07
 */
@Controller
@RequestMapping(value = "${adminPath}/tools/email")
public class EmailController extends BaseController {
 
    @Autowired
    private SystemConfigService systemConfigService;
    
    /**
     * 打开邮件页面
     */
    @RequestMapping(value = {"index", ""})
    public String index( HttpServletRequest request, HttpServletResponse response, Model model) {
        return "modules/tools/sendEmail";
    }
 
    /**
     * 发送邮件
     */
    @RequestMapping("send")
    public String send(String emailAddress,  HttpServletResponse response, String title, String content, Model model) throws Exception {
        SystemConfig config = systemConfigService.get("1");
        String[]addresses = emailAddress.split(";");
        String result = "";
        for(String address: addresses){
            boolean isSuccess = MailSendUtils.sendEmail(config.getSmtp(), config.getPort(), config.getMailName(), config.getMailPassword(),address,  title, content, "0");
            if(isSuccess){
                result += address+":<font color='green'>发送成功!</font><br/>";
            }else{
                result += address+":<font color='red'>发送失败!</font><br/>";
            }
        }
            model.addAttribute("result", result);
            return "modules/tools/sendEmailResult";
    }
        
}