From d83894756aa6abe27addf58f16a967b781df409e Mon Sep 17 00:00:00 2001 From: hylee Date: Thu, 8 Jun 2023 11:06:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B0=84=ED=8C=90=EB=8B=A4=EC=9B=80=20?= =?UTF-8?q?=EA=B2=AC=EC=A0=81=EC=9D=98=EB=A2=B0=20=EB=A9=94=EC=9D=BC?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 15 +- .../com/itn/mjonApi/cmn/aop/LogAspect.java | 3 - .../etc/ganpandaum/mapper/domain/GdVO.java | 38 ++++ .../etc/ganpandaum/service/GdService.java | 21 ++ .../service/impl/GdServiceImpl.java | 131 +++++++++++ .../etc/ganpandaum/web/GdRestController.java | 53 +++++ .../send/service/impl/SendServiceImpl.java | 2 +- .../mjon/api/send/web/SendRestController.java | 17 +- .../com/itn/mjonApi/util/Email/EmailVO.java | 44 ++++ .../mjonApi/util/Email/SMTPAuthenticator.java | 28 +++ .../com/itn/mjonApi/util/Email/SendMail.java | 208 ++++++++++++++++++ src/main/resources/application.properties | 7 +- 12 files changed, 551 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/itn/mjonApi/etc/ganpandaum/mapper/domain/GdVO.java create mode 100644 src/main/java/com/itn/mjonApi/etc/ganpandaum/service/GdService.java create mode 100644 src/main/java/com/itn/mjonApi/etc/ganpandaum/service/impl/GdServiceImpl.java create mode 100644 src/main/java/com/itn/mjonApi/etc/ganpandaum/web/GdRestController.java create mode 100644 src/main/java/com/itn/mjonApi/util/Email/EmailVO.java create mode 100644 src/main/java/com/itn/mjonApi/util/Email/SMTPAuthenticator.java create mode 100644 src/main/java/com/itn/mjonApi/util/Email/SendMail.java diff --git a/pom.xml b/pom.xml index c59a9ae..6878096 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ org.springframework.boot spring-boot-devtools - true + @@ -135,6 +135,19 @@ spring-boot-starter-validation + + + javax.mail + mail + 1.4.7 + + + + org.jsoup + jsoup + 1.15.3 + + diff --git a/src/main/java/com/itn/mjonApi/cmn/aop/LogAspect.java b/src/main/java/com/itn/mjonApi/cmn/aop/LogAspect.java index a54e8eb..9b3e94a 100644 --- a/src/main/java/com/itn/mjonApi/cmn/aop/LogAspect.java +++ b/src/main/java/com/itn/mjonApi/cmn/aop/LogAspect.java @@ -106,7 +106,6 @@ public class LogAspect { public void afterReturning(JoinPoint joinPoint, Object returnValue) throws Exception { log.info(" :: AfterReturning :: "); - String resutlCode = ""; // HttpServletRequest 객체를 가져옴 HttpServletRequest request = this.getHttpServletRequest(); // @Befer에서 저장한 logId를 가져옴 @@ -117,9 +116,7 @@ public class LogAspect { LettnAccessLogVO lettnAccessLogVO = new LettnAccessLogVO() .builder() .logId(logId) -// .resCn(this.getJsonToString(returnValue)) .resCn(this.getJsonToString(returnValue)) - .resCode(resutlCode) .build(); lettnAccessLogMapper.update(lettnAccessLogVO); } diff --git a/src/main/java/com/itn/mjonApi/etc/ganpandaum/mapper/domain/GdVO.java b/src/main/java/com/itn/mjonApi/etc/ganpandaum/mapper/domain/GdVO.java new file mode 100644 index 0000000..726dec1 --- /dev/null +++ b/src/main/java/com/itn/mjonApi/etc/ganpandaum/mapper/domain/GdVO.java @@ -0,0 +1,38 @@ +package com.itn.mjonApi.etc.ganpandaum.mapper.domain; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +/** + * packageName : com.itn.mjonApi.etc.ganpandaum.mapper.domain + * fileName : GdVO + * author : hylee + * date : 2023-06-07 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 2023-06-07 hylee 최초 생성 + */ + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class GdVO { + + private String gdName; + private String gdCompany; + private String gdPhone; + private String gdEmail; + private String gdAddr; + private String gdContent; + private List fileInfo; + + +} diff --git a/src/main/java/com/itn/mjonApi/etc/ganpandaum/service/GdService.java b/src/main/java/com/itn/mjonApi/etc/ganpandaum/service/GdService.java new file mode 100644 index 0000000..b7f7724 --- /dev/null +++ b/src/main/java/com/itn/mjonApi/etc/ganpandaum/service/GdService.java @@ -0,0 +1,21 @@ +package com.itn.mjonApi.etc.ganpandaum.service; + +import com.itn.mjonApi.cmn.msg.RestResponse; +import com.itn.mjonApi.etc.ganpandaum.mapper.domain.GdVO; + +import java.io.IOException; + +/** + * packageName : com.itn.mjonApi.etc.ganpandaum.service + * fileName : GdService + * author : hylee + * date : 2023-06-07 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 2023-06-07 hylee 최초 생성 + */ +public interface GdService { + RestResponse sendEstimateEmail(GdVO gdVO) throws IOException; +} diff --git a/src/main/java/com/itn/mjonApi/etc/ganpandaum/service/impl/GdServiceImpl.java b/src/main/java/com/itn/mjonApi/etc/ganpandaum/service/impl/GdServiceImpl.java new file mode 100644 index 0000000..b9a733c --- /dev/null +++ b/src/main/java/com/itn/mjonApi/etc/ganpandaum/service/impl/GdServiceImpl.java @@ -0,0 +1,131 @@ +package com.itn.mjonApi.etc.ganpandaum.service.impl; + +import com.itn.mjonApi.cmn.msg.RestResponse; +import com.itn.mjonApi.etc.ganpandaum.mapper.domain.GdVO; +import com.itn.mjonApi.etc.ganpandaum.service.GdService; +import com.itn.mjonApi.util.Email.EmailVO; +import com.itn.mjonApi.util.Email.SendMail; +import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; +import org.jsoup.Jsoup; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.time.LocalDate; + +/** + * packageName : com.itn.mjonApi.etc.ganpandaum.service.impl + * fileName : GdServiceImpl + * author : hylee + * date : 2023-06-07 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 2023-06-07 hylee 최초 생성 + */ +@Service +@Slf4j +public class GdServiceImpl implements GdService { + + @Value("${Ganpandaup.estimate.template.url}") + private String GANPANDAUP_ESTIMATE_TEMPLATE_URL; + + @Value("${respone.status.success}") + private String RESPONE_STATUS_SUCCESS; + + @Value("${Ganpandaup.receiver.email}") + private String GANPANDAUP_RECEIVER_EMAIL; + + @Override + public RestResponse sendEstimateEmail(GdVO gdVO) throws IOException { + + + log.info("gdVO: [{}]", gdVO.toString()); + log.info("gdVO: [{}]", gdVO.getFileInfo().get(0).getOriginalFilename()); + + MultipartFile multipartFile = gdVO.getFileInfo().get(0); + +// File p_file = new File(multipartFile.getOriginalFilename()); +// multipartFile.transferTo(p_file); + +// File p_file = multipartFile.transferTo(p_file); + + File p_file = getFile(gdVO, multipartFile); + + + String returnMsg = "문의해 주셔서 감사합니다.\n빠른 시일 내에 답변해 드리겠습니다."; + HttpStatus status = HttpStatus.OK; + + String emailContent = ""; + SendMail sMail = new SendMail(); + + try { + emailContent = Jsoup.connect(GANPANDAUP_ESTIMATE_TEMPLATE_URL) + .data("query", "Java") + .userAgent("Mozilla") + .cookie("auth", "token") + .timeout(3000) + .post() + .toString(); + // ./src/main/resources/templates/estimate.html + emailContent = emailContent + .replace("[[_Company_]]", gdVO.getGdCompany()) + .replace("[[_Name_]]", gdVO.getGdName()) + .replace("[[_Phone_]]", gdVO.getGdPhone()) + .replace("[[_Email_]]", gdVO.getGdEmail()) + .replace("[[_Addr_]]", gdVO.getGdAddr()) + .replace("[[_Content_]]", gdVO.getGdContent()) + ; + + + + // 메일 첨부파일을 위한 절대경로 + // 메일 제목 + String mailTitle = "[간판다움 견적의뢰] "+gdVO.getGdName()+"["+gdVO.getGdCompany()+"]님의 견적 의뢰입니다._"+LocalDate.now(); + + sMail.itnSendMail( + EmailVO.builder() + .title(mailTitle) + .contents(emailContent) + .fileInfo(p_file) + .atch_file_name(p_file.getName()) + .send_to(GANPANDAUP_RECEIVER_EMAIL) + .send_from("noreply@munjaon.co.kr") + .build() + ); + + } + catch (IOException e) { + e.printStackTrace(); + return new RestResponse("STAT_1099"); + } + catch (Exception e) { + e.printStackTrace(); + return new RestResponse("STAT_1099"); + } + + + + + + +// return null; + return new RestResponse(RESPONE_STATUS_SUCCESS); + } + + @NotNull + private static File getFile(GdVO gdVO, MultipartFile multipartFile) throws IOException { + File p_file = new File(gdVO.getFileInfo().get(0).getOriginalFilename()); + p_file.createNewFile(); + FileOutputStream fos = new FileOutputStream(p_file); + fos.write(multipartFile.getBytes()); + fos.close(); + return p_file; + } +} diff --git a/src/main/java/com/itn/mjonApi/etc/ganpandaum/web/GdRestController.java b/src/main/java/com/itn/mjonApi/etc/ganpandaum/web/GdRestController.java new file mode 100644 index 0000000..c26969e --- /dev/null +++ b/src/main/java/com/itn/mjonApi/etc/ganpandaum/web/GdRestController.java @@ -0,0 +1,53 @@ +package com.itn.mjonApi.etc.ganpandaum.web; + +import com.itn.mjonApi.cmn.msg.RestResponse; +import com.itn.mjonApi.etc.ganpandaum.mapper.domain.GdVO; +import com.itn.mjonApi.etc.ganpandaum.service.GdService; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * packageName : com.itn.mjonApi.etc.ganpandaum.web + * fileName : SendRestController + * author : hylee + * date : 2023-02-15 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 2023-02-15 hylee 최초 생성 + */ + +// 치환문자가 있으면 , => §로 치환 + +@Slf4j +@RestController +public class GdRestController { + + + @Autowired + private GdService gdService; + + + /** + * + * @param gdVO + * @Discription [문자 발송] 같은 내용으로 여려명에게 보냄 + * @return + */ + @CrossOrigin("*") // 모든 요청에 접근 허용 + @PostMapping("/etc/ganpandaum/sendEstimateEmail") + @ApiOperation(value= "단문 문자 전송", notes = " 같은 내용으로 여러명에게 보냄") + public ResponseEntity sendEstimateEmail(GdVO gdVO) throws Exception { + return ResponseEntity.ok().body(gdService.sendEstimateEmail(gdVO)); + } + + + + +} diff --git a/src/main/java/com/itn/mjonApi/mjon/api/send/service/impl/SendServiceImpl.java b/src/main/java/com/itn/mjonApi/mjon/api/send/service/impl/SendServiceImpl.java index d51e0ae..5b476ac 100644 --- a/src/main/java/com/itn/mjonApi/mjon/api/send/service/impl/SendServiceImpl.java +++ b/src/main/java/com/itn/mjonApi/mjon/api/send/service/impl/SendServiceImpl.java @@ -506,7 +506,7 @@ public class SendServiceImpl implements SendService { break; } - return statCode; + return "STAT_"+statCode; } } diff --git a/src/main/java/com/itn/mjonApi/mjon/api/send/web/SendRestController.java b/src/main/java/com/itn/mjonApi/mjon/api/send/web/SendRestController.java index 1bf342d..2a59c08 100644 --- a/src/main/java/com/itn/mjonApi/mjon/api/send/web/SendRestController.java +++ b/src/main/java/com/itn/mjonApi/mjon/api/send/web/SendRestController.java @@ -1,20 +1,17 @@ package com.itn.mjonApi.mjon.api.send.web; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; - import com.itn.mjonApi.cmn.msg.RestResponse; import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO; import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgsRequestVO; import com.itn.mjonApi.mjon.api.send.service.SendService; - import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; /** * packageName : com.itn.mjonApi.mjon.send.web @@ -52,7 +49,7 @@ public class SendRestController { */ @CrossOrigin("*") // 모든 요청에 접근 허용 @PostMapping("/api/send/sendMsg") - @ApiOperation(value= "단문 문자 전송", notes = "같은 내용으로 여러명에게 보냄") + @ApiOperation(value= "단문 문자 전송", notes = " 같은 내용으로 여러명에게 보냄") public ResponseEntity sendMsg(MsgRequestVO msgRequestVO) throws Exception { return ResponseEntity.ok().body(sendService.sendMsgData(msgRequestVO)); } diff --git a/src/main/java/com/itn/mjonApi/util/Email/EmailVO.java b/src/main/java/com/itn/mjonApi/util/Email/EmailVO.java new file mode 100644 index 0000000..7d5daa6 --- /dev/null +++ b/src/main/java/com/itn/mjonApi/util/Email/EmailVO.java @@ -0,0 +1,44 @@ +package com.itn.mjonApi.util.Email; + +import lombok.*; + +import java.io.File; +import java.util.Date; + +/** + * packageName : com.itn.mjonApi.util.Email + * fileName : EmailVO + * author : hylee + * date : 2023-06-07 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 2023-06-07 hylee 최초 생성 + */ +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class EmailVO { + + + private int idx; + private int pro_idx; + private String title; + private String category; + private String contents; + private String send_from; + private String send_to; + private Date senddate; + private Date regdate; + private String status; + private String flag; + private String target; + private String atch_file_id; + private String atch_file_name; + private String atch_file_path; + private File fileInfo; + +} diff --git a/src/main/java/com/itn/mjonApi/util/Email/SMTPAuthenticator.java b/src/main/java/com/itn/mjonApi/util/Email/SMTPAuthenticator.java new file mode 100644 index 0000000..1ba4568 --- /dev/null +++ b/src/main/java/com/itn/mjonApi/util/Email/SMTPAuthenticator.java @@ -0,0 +1,28 @@ +package com.itn.mjonApi.util.Email; + +import javax.mail.Authenticator; +import javax.mail.PasswordAuthentication; + +/** + * packageName : com.itn.mjonApi.util.Email + * fileName : SMTPAuthenticator + * author : hylee + * date : 2023-06-07 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 2023-06-07 hylee 최초 생성 + */ +public class SMTPAuthenticator extends Authenticator { + + protected PasswordAuthentication getPasswordAuthentication() { + //https://myaccount.google.com/lesssecureapps 에서 보안 수준 낮은 앱의 액세스 허용 해줘야함(인증 오류날때) +// String username = "itn0801@gmail.com"; // gmail 사용자; + String username = "noreply@munjaon.co.kr"; // naverworks 사용자; + /*String password = "easytour7!"; // 패스워드;*/ +// String password = "jpkofmptitmqvbhc"; // 패스워드; + String password = "iEWkihhyZipl"; // 패스워드; + return new PasswordAuthentication(username, password); + } +} diff --git a/src/main/java/com/itn/mjonApi/util/Email/SendMail.java b/src/main/java/com/itn/mjonApi/util/Email/SendMail.java new file mode 100644 index 0000000..652a583 --- /dev/null +++ b/src/main/java/com/itn/mjonApi/util/Email/SendMail.java @@ -0,0 +1,208 @@ +package com.itn.mjonApi.util.Email; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpStatus; + +import javax.activation.DataHandler; +import javax.activation.FileDataSource; +import javax.mail.*; +import javax.mail.internet.*; +import java.util.Date; +import java.util.Properties; + +/** + * packageName : com.itn.mjonApi.util + * fileName : SendMail + * author : hylee + * date : 2023-06-07 + * description : + * =========================================================== + * DATE AUTHOR NOTE + * ----------------------------------------------------------- + * 2023-06-07 hylee 최초 생성 + */ +public class SendMail { + + public void sendMail(EmailVO vo) throws Exception { + + try { + + Properties props = new Properties(); + + /* + * props.put("mail.transport.protocol", "smtp");// 프로토콜 설정 + * props.put("mail.smtp.host", "smtp.gmail.com");// gmail SMTP 서비스 주소(호스트) + * props.put("mail.smtp.port", "465");// gmail SMTP 서비스 포트 설정 + * props.put("mail.smtp.starttls.enable","true"); // gmail 인증용 Secure Socket + * Layer(SSL) 설정 props.setProperty("mail.smtp.socketFactory.class", + * "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true");// + * SMTP 인증을 설정 props.put("mail.debug", "true"); // log를 위한 debug 옵션 추가 + */ + + props.put("mail.smtp.auth", "true");// SMTP 인증을 설정 + props.put("mail.smtp.starttls.enable", "true"); + // props.put("mail.transport.protocol", "smtp");// 프로토콜 설정 + props.put("mail.smtp.host", "smtp.gmail.com");// gmail SMTP 서비스 주소(호스트) + props.put("mail.smtp.port", "587");// gmail SMTP 서비스 포트 설정 + props.put("mail.smtp.ssl.trust", "smtp.gmail.com"); + props.put("mail.smtp.ssl.protocols", "TLSv1.2"); +// props.put("mail.smtp.debug", "true"); + // gmail 인증용 Secure Socket Layer(SSL) 설정 + props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + + // 인증정보 + Authenticator auth = new SMTPAuthenticator(); + + Session mailSession = Session.getDefaultInstance(props, auth); + + // MimeMessage mailMessage = mailImpl.createMimeMessage(); + + MimeMessage message = new MimeMessage(mailSession); + + InternetAddress from = new InternetAddress(vo.getSend_from()); + message.setFrom(from); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(vo.getSend_to())); + message.setSubject(vo.getTitle()); + message.setContent(vo.getContents(), "text/html;charset=UTF-8"); + // message.setText(vo.getContents()); + message.setSentDate(new Date()); + + Transport.send(message); + + } catch (MessagingException e) { + e.printStackTrace(); + } + } + + public void sendMail2(EmailVO vo) throws Exception { + + try { + + Properties props = new Properties(); + + /* + * props.put("mail.transport.protocol", "smtp");// 프로토콜 설정 + * props.put("mail.smtp.host", "smtp.gmail.com");// gmail SMTP 서비스 주소(호스트) + * props.put("mail.smtp.port", "465");// gmail SMTP 서비스 포트 설정 + * props.put("mail.smtp.starttls.enable","true"); // gmail 인증용 Secure Socket + * Layer(SSL) 설정 props.setProperty("mail.smtp.socketFactory.class", + * "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true");// + * SMTP 인증을 설정 props.put("mail.debug", "true"); // log를 위한 debug 옵션 추가 + */ + +// props.put("mail.smtp.auth", "true");// SMTP 인증을 설정 +// props.put("mail.smtp.starttls.enable","true"); +// //props.put("mail.transport.protocol", "smtp");// 프로토콜 설정 +// props.put("mail.smtp.host", "smtp.worksmobile.com");// gmail SMTP 서비스 주소(호스트) +// props.put("mail.smtp.port", "587");// gmail SMTP 서비스 포트 설정 +// /*props.put("mail.smtp.ssl.trust","smtp.gmail.com"); +// props.put("mail.smtp.ssl.protocols", "TLSv1.2");*/ +// props.put("mail.smtp.starttls.enable","true"); +// props.put("mail.smtp.debug", "true"); + // gmail 인증용 Secure Socket Layer(SSL) 설정 +// props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory"); + + // worksmobile 계정 설정 + props.put("mail.smtp.host", "smtp.worksmobile.com"); + props.put("mail.smtp.socketFactory.port", "465"); + props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + props.put("mail.smtp.auth", "true"); + props.put("mail.smtp.port", "465"); + props.put("mail.smtp.ssl.enable", "true"); + props.put("mail.smtp.ssl.trust", "smtp.worksmobile.com"); + props.put("mail.smtp.ssl.protocols", "TLSv1.2"); +// props.put("mail.smtp.debug", "true"); + + // 인증정보 + Authenticator auth = new SMTPAuthenticator(); + + Session mailSession = Session.getDefaultInstance(props, auth); + + /* + * Session mailSession = Session.getInstance(props, new + * javax.mail.Authenticator() { protected PasswordAuthentication + * getPasswordAuthentication() { return new + * PasswordAuthentication("noreply@munjaon.co.kr", "easytour7!"); } }); + */ + +// mailSession.setDebug(true); + + // MimeMessage mailMessage = mailImpl.createMimeMessage(); + + MimeMessage message = new MimeMessage(mailSession); + + InternetAddress from = new InternetAddress(vo.getSend_from()); + message.setFrom(from); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(vo.getSend_to())); + message.setSubject(vo.getTitle()); + message.setContent(vo.getContents(), "text/html;charset=UTF-8"); + // message.setText(vo.getContents()); + message.setSentDate(new Date()); + + Transport.send(message); + + } catch (MessagingException e) { + e.printStackTrace(); + } + } + + // public SuccessResponse itnSendMail(EmailVO vo) throws Exception { + public void itnSendMail(EmailVO vo) throws Exception { + + Properties props = new Properties(); + + String returnMsg = "지원해 주셔서 감사합니다."; + HttpStatus status = HttpStatus.OK; + + // worksmobile 계정 설정 + props.put("mail.smtp.host", "smtp.worksmobile.com"); + props.put("mail.smtp.socketFactory.port", "465"); + props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + props.put("mail.smtp.auth", "true"); + props.put("mail.smtp.port", "465"); + props.put("mail.smtp.ssl.enable", "true"); + props.put("mail.smtp.ssl.trust", "smtp.worksmobile.com"); + props.put("mail.smtp.ssl.protocols", "TLSv1.2"); + +// props.put("mail.smtp.debug", "true"); + + + // 인증정보 + Authenticator auth = new SMTPAuthenticator(); + Session mailSession = Session.getDefaultInstance(props, auth); + Multipart mp = new MimeMultipart(); + + // 파일 영역 + if(StringUtils.isNotEmpty(vo.getAtch_file_name())) + { + MimeBodyPart mailFile = new MimeBodyPart(); + FileDataSource fds = new FileDataSource(vo.getFileInfo()); +// FileDataSource fds = new FileDataSource(new File(vo.getAtch_file_path()).getAbsolutePath()); + mailFile.setDataHandler(new DataHandler(fds)); + mailFile.setFileName(MimeUtility.encodeText(vo.getAtch_file_name(), "euc-kr","B")); + mp.addBodyPart(mailFile); + } + + //메일 영역 + MimeBodyPart mailInfo = new MimeBodyPart(); + mailInfo.setContent(vo.getContents(), "text/html; charset=UTF-8"); + mp.addBodyPart(mailInfo); + +// mailSession.setDebug(true); + MimeMessage message = new MimeMessage(mailSession); + + message.setFrom(new InternetAddress(vo.getSend_from())); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(vo.getSend_to())); + message.setSubject(vo.getTitle()); + message.setContent(vo.getContents(), "text/html;charset=UTF-8"); + message.setSentDate(new Date()); + + + message.setContent(mp); + + Transport.send(message); + +// return new SuccessResponse(status, returnMsg, LocalDateTime.now()); + } +} + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1db78a7..5adb4d1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,4 +22,9 @@ spring.devtools.livereload.enabled=true server.error.whitelabel.enabled=false # respone success status code -respone.status.success=STAT_0 \ No newline at end of file +respone.status.success=STAT_0 + + +# +Ganpandaup.estimate.template.url=https://www.munjaon.co.kr/publish/email_form_ganpandaum_contact.html +Ganpandaup.receiver.email=hylee250@kakao.com \ No newline at end of file