// Path: src/main/java/cn/edu/upc/yb/integrate/sighup/utils/MailUtils.java
// public class MailUtils {
// 
//     public static String HOST = "smtp.sina.com";
// 
//     public static String PROTOCOL = "smtp";
// 
//     public static int PORT = 25;
// 
//     public static String FROM = "upcmvc@sina.com";//发件人的email
// 
//     public static String PWD = "qilu2016";//发件人密码
// 
//     /**
//      * 获取Session
//      *
//      * @return
//      */
//     private static Session getSession() {
//         Properties props = new Properties();
//         props.put("mail.smtp.host", HOST);//设置服务器地址
//         props.put("mail.store.protocol", PROTOCOL);//设置协议
//         props.put("mail.smtp.port", PORT);//设置端口
//         props.put("mail.smtp.auth", "true");
// 
//         Authenticator authenticator = new Authenticator() {
//             @Override
//             protected PasswordAuthentication getPasswordAuthentication() {
//                 return new PasswordAuthentication(FROM, PWD);
//             }
// 
//         };
//         Session session = Session.getDefaultInstance(props, authenticator);
// //        session.setDebug(true);
// 
//         return session;
//     }
// 
//     public static void send(String toEmail, String content) {
//         Session session = getSession();
//         try {
//             System.out.println("--send--" + content);
//             // Instantiate a message
//             Message msg = new MimeMessage(session);
// 
//             //Set message attributes
//             msg.setFrom(new InternetAddress(FROM));
//             InternetAddress[] address = {new InternetAddress(toEmail)};
//             msg.setRecipients(Message.RecipientType.TO, address);
//             msg.setSubject("邮件");
//             msg.setSentDate(new Date());
//             msg.setContent(content, "text/html;charset=utf-8");
//             msg.saveChanges();
// 
//             //Send the message
//             Transport.send(msg);
//             System.out.println("发送完成");
//         } catch (MessagingException mex) {
//             mex.printStackTrace();
//         }
//     }
// }


import cn.edu.upc.yb.integrate.sighup.model.SighUp;
import cn.edu.upc.yb.integrate.sighup.repository.SighUpRepository;
import cn.edu.upc.yb.integrate.sighup.utils.MailUtils;
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 org.springframework.web.bind.annotation.RequestMethod;
package cn.edu.upc.yb.integrate.sighup.controller;


/**
 * Created by Jaxlying on 2016/9/27.
 */
@Controller
@RequestMapping("/sighup")
public class SighupController {

    @Autowired
    private SighUpRepository sighUpRepository;

    @RequestMapping(value = "",method = RequestMethod.POST)
    public String send(Model model,String name,String major,String sex,String detail,String method){
        SighUp sighUp = new SighUp(name, sex, method,  detail,  major);
        sighUpRepository.save(sighUp);
        MailUtils mailUtils = new MailUtils();
        mailUtils.send("upcybdevelopment@outlook.com","name: " + name + "</br>" +
                "性别:" + sex + "</br>" +
                 "专业班级: " + major +"</br>" +
// Path: src/main/java/cn/edu/upc/yb/integrate/sighup/utils/MailUtils.java
// public class MailUtils {
// 
//     public static String HOST = "smtp.sina.com";
// 
//     public static String PROTOCOL = "smtp";
// 
//     public static int PORT = 25;
// 
//     public static String FROM = "upcmvc@sina.com";//发件人的email
// 
//     public static String PWD = "qilu2016";//发件人密码
// 
//     /**
//      * 获取Session
//      *
//      * @return
//      */
//     private static Session getSession() {
//         Properties props = new Properties();
//         props.put("mail.smtp.host", HOST);//设置服务器地址
//         props.put("mail.store.protocol", PROTOCOL);//设置协议
//         props.put("mail.smtp.port", PORT);//设置端口
//         props.put("mail.smtp.auth", "true");
// 
//         Authenticator authenticator = new Authenticator() {
//             @Override
//             protected PasswordAuthentication getPasswordAuthentication() {
//                 return new PasswordAuthentication(FROM, PWD);
//             }
// 
//         };
//         Session session = Session.getDefaultInstance(props, authenticator);
// //        session.setDebug(true);
// 
//         return session;
//     }
// 
//     public static void send(String toEmail, String content) {
//         Session session = getSession();
//         try {
//             System.out.println("--send--" + content);
//             // Instantiate a message
//             Message msg = new MimeMessage(session);
// 
//             //Set message attributes
//             msg.setFrom(new InternetAddress(FROM));
//             InternetAddress[] address = {new InternetAddress(toEmail)};
//             msg.setRecipients(Message.RecipientType.TO, address);
//             msg.setSubject("邮件");
//             msg.setSentDate(new Date());
//             msg.setContent(content, "text/html;charset=utf-8");
//             msg.saveChanges();
// 
//             //Send the message
//             Transport.send(msg);
//             System.out.println("发送完成");
//         } catch (MessagingException mex) {
//             mex.printStackTrace();
//         }
//     }
// }


// Path: src/main/java/cn/edu/upc/yb/integrate/sighup/controller/SighupController.java
import cn.edu.upc.yb.integrate.sighup.model.SighUp;
import cn.edu.upc.yb.integrate.sighup.repository.SighUpRepository;
import cn.edu.upc.yb.integrate.sighup.utils.MailUtils;
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 org.springframework.web.bind.annotation.RequestMethod;

package cn.edu.upc.yb.integrate.sighup.controller;


/**
 * Created by Jaxlying on 2016/9/27.
 */
@Controller
@RequestMapping("/sighup")
public class SighupController {

    @Autowired
    private SighUpRepository sighUpRepository;

    @RequestMapping(value = "",method = RequestMethod.POST)
    public String send(Model model,String name,String major,String sex,String detail,String method){
        SighUp sighUp = new SighUp(name, sex, method,  detail,  major);
        sighUpRepository.save(sighUp);
        MailUtils mailUtils = new MailUtils();
        mailUtils.send("upcybdevelopment@outlook.com","name: " + name + "</br>" +
                "性别:" + sex + "</br>" +
                 "专业班级: " + major +"</br>" +
                "个人简介:" + detail + "</br>" +