package nlib.mail;
 
import java.io.Reader;
import java.util.Properties;

import javax.mail.internet.MimeMessage;

import org.apache.ibatis.io.Resources;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import nlib.mail.service.EmailVO;
 

/**
 * <pre>
 * @Class Name : EmailSender.java
 * 
 * @Description : 메일전송
 * 
 * 
 * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
 *
 * </pre>
 *
 * @ ------------    --------    ---------------------------
 * @ 수정일                     수정자             수정내용
 * @ ------------    --------    ---------------------------
 * @ 2021. 7. 21.    JSYOO       최초 생성
 * @ 2021.10. 14.    KNKIM       대출목록 API방식 변경 및 화면설계서 적용 개발 
 *
 * 
 * @author 이씨플라자 * DIGITALSHIP JSYOO
 * @since 2021. 7. 21.
 * @version 1.0
 *
 */
@Component
public class EmailSender  {
     
    @Autowired
    protected JavaMailSender  mailSender;
 
    /**
     * 메일전송
     * @param email
     * @throws Exception
     */
    public void SendEmail(EmailVO email) throws Exception {
    	String resource = "egovframework/egovProps/globals.properties";
        Properties properties = new Properties();
    	
        Reader reader = Resources.getResourceAsReader(resource);
        properties.load(reader);
        
        String senderName = properties.getProperty("system.notification.email.sender.name");
        String sender = properties.getProperty("system.notification.email.sender");
        
        MimeMessage msg = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(msg, true, "utf-8");
        helper.setText(email.getContent(), true);	//***HTML 적용
		helper.setTo(email.getReciver());
		helper.setSubject(email.getSubject());
		helper.setFrom(sender,senderName);

        mailSender.send(msg); 
    }
}