package kcc.ve.cmm;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import kcc.com.cmm.LoginVO;
import kcc.com.cmm.service.EgovFileMngUtil;
import kcc.ve.instr.tngrVisitEdu.eduInfo.service.VEEduAplctVO;
public class VeSendMail {
private static final Logger LOGGER = LoggerFactory.getLogger(EgovFileMngUtil.class);
//================================================================
//찾교 메일 발송 계정 ID, PW 넣는 부분
//테스트를 위한 저작위 공통 계정 ID: no-reply@copyright.or.kr PW: Copycopy12!
//찾교만 추가되어 찾교는 현재 메일발송 안됨_220221
//기존(찾교청소년) ID: school@copyright.or.kr PW: 연수원2669!
//신규(찾교성인) ID: edu@copyright.or.kr PW: Copy0723!
//기존(체험교실) ID: entt@copyright.or.kr PW: edu0213**
//신규(외부협력) ID: cev@copyright.or.kr PW: Copy0723!
//================================================================
//파라미터 정리
//1. sndFlag = 메뉴 구분
// C -> 찾교청소년
// S -> 찾교성인
// G -> 체험교실
// W -> 외부협력
//2. sndTo = 수신자
//3. vEEduAplctVO = eduAplctOrd(pk)
// sndHstryOrd(pk)
// sndCd(10 - sms, 20 - email)
// sndId(발송자)
// sndCn(발송내용)
//================================================================
public String VeSendMail(String sndFlag, String sndTo, VEEduAplctVO vEEduAplctVO, LoginVO loginVO) throws Exception {
String result = "success";
System.out.println("vEEduAplctVO.getClphone1()");
System.out.println(sndFlag);
System.out.println(vEEduAplctVO.getClphone1());
System.out.println(vEEduAplctVO.getClphone2());
System.out.println("vEEduAplctVO.getClphone2()");
try {
System.out.println("수정_2200317_12:46");
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "smtp.gov-dooray.com");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.ssl.enable", "true");
// props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.protocols", "TLSv1");
props.put("mail.smtp.ssl.protocols", "TLSv1.1");
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
props.put("mail.debug", "true");
Authenticator authenticator = new Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
String id = "no-reply@copyright.or.kr";
String pw = "Copycopy12!";
/*231120 - 성인 교육용 메일 정보 불일치 > 전부 청소년 메일로 우선 사용*/
id = "school@copyright.or.kr";
pw = "dustndnjs2669!";
/*if("C".equals(sndFlag) || "Z".equals(sndFlag)) {
id = "school@copyright.or.kr";
//pw = "연수원2669!";
pw = "dustndnjs2669!";
}else if("S".equals(sndFlag)) {
id = "kedu@copyright.or.kr";
pw = "Copy0723!";
}else if("G".equals(sndFlag)) {
id = "entt@copyright.or.kr";
pw = "edu0213**";
}else if("W".equals(sndFlag)) {
id = "cev@copyright.or.kr";
pw = "Copy0723!";
}else if("UR".equals(sndFlag)) {
id = vEEduAplctVO.getClphone1();
pw = vEEduAplctVO.getClphone2();
}*/
System.out.println(id);
System.out.println(pw);
System.out.println("vEEduAplctVO.getClphone3()");
return new PasswordAuthentication(id,pw);
}
};
Session session = Session.getInstance(props, authenticator) ;
MimeMessage message = new MimeMessage(session);
//메일 내용
String Cn = vEEduAplctVO.getSndCn();
//메일 내용 textarea 작성 시, 메일에 Enter 반영
if(!"".equals(Cn) && Cn != null) {
Cn = Cn.replaceAll("\n", "
");
}
//메일제목
message.setSubject("[한국저작권위원회] 찾아가는 교육서비스_알림");
//발송메일 주소
String fromAddr = "no-reply@copyright.or.kr";
if("C".equals(sndFlag)) {
fromAddr = "school@copyright.or.kr";
}else if("Z".equals(sndFlag)) {
fromAddr = "school@copyright.or.kr";
message.setSubject("[한국저작권위원회] 찾아가는 저작권 교육관련 협조요청 사항");
}else if("S".equals(sndFlag)) {
fromAddr = "kedu@copyright.or.kr";
}else if("G".equals(sndFlag)) {
fromAddr = "entt@copyright.or.kr";
}else if("W".equals(sndFlag)) {
fromAddr = "cev@copyright.or.kr";
//메일제목
message.setSubject("[한국저작권위원회] 저작권 교육콘텐츠 수령 방법 안내");
//메일내용
Cn = "\r\n" +
"\r\n" +
"
\r\n" +
" \r\n" +
" | \r\n" +
"
| \r\n" +
" \r\n" +
" 안녕하세요~ | \r\n" +
"
| \r\n" + " | \r\n" + "