package com.izouma.awesomeadmin.web;

import com.izouma.awesomeadmin.dto.MailInfo;
import com.izouma.awesomeadmin.dto.Result;
import com.izouma.awesomeadmin.util.MailUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>页面控制。</p>
 *
 * @author 姓名 <br />
 * 更新履历 <br />
 * 日期 : 姓名: 更新内容<br />
 * @version 1.0
 */
@Controller
@RequestMapping("/mail")
public class MailSenderController {

    @RequestMapping(value = "/send", method = RequestMethod.GET)
    @ResponseBody
    public Result send(@RequestParam(required = true, value = "mobile") String mobile,
                       @RequestParam(required = true, value = "address") String address,
                       @RequestParam(required = true, value = "message") String message,
                       @RequestParam(required = true, value = "mail") String mail) {

        try {
            MailInfo mailInfo = new MailInfo();
            List<String> toList = new ArrayList<String>();
            toList.add(mail);


            mailInfo.setToAddress(toList);//收件人

            mailInfo.setSubject("一米世界留言版");
            String content = "<h1>手机：" + mobile + " </h1>"
                    + "<h1>地址：" + address + "</h1>"
                    + "<h1>留言：" + message + "</h1>";
            mailInfo.setContent(content);

            MailUtil.sendEmail(mailInfo);

            return new Result(true, "发送成功");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new Result(false, "发送失败，请稍后重试");
    }

}
