티스토리 뷰

Skill/spring

java] 메일 보내기

진열사랑 2025. 3. 4. 22:06

@RequestMapping("/boffice/emailTest.do")
    @ResponseBody
public String mainTest(ActManageDefaultVO searchVO, ModelMap model) throws Exception {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost("127.0.0.1");
        mailSender.setPort(25);
        // Optional: mailSender.setUsername("your-username");
        // Optional: mailSender.setPassword("your-password");

        // JavaMail Properties 설정
        Properties props = mailSender.getJavaMailProperties();
        //props.put("mail.smtp.auth", "false");
        //props.put("mail.smtp.starttls.enable", "false");
        props.put("mail.debug", "true");  // SMTP 통신 디버그 로그 활성화

        // 메일 메시지 생성
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("****@nate.com");
        message.setTo("****@nate.com");
        message.setSubject("Test Subject");
        message.setText("Test mail content");

        try {
            // 메일 전송 및 로그 확인
            System.out.println("Attempting to send email...");
            mailSender.send(message);
            System.out.println("Email sent successfully");

        } catch (Exception e) {
            System.err.println("Failed to send email: " + e.getMessage());
            e.printStackTrace();
        }

/*String mailFolder = context.getRealPath("/html/mail/");
String mailTpl = mailFolder+"/mail.html";
String mailSubject = "문의글 답변 승인 부탁드립니다.";
String mailHtml = "";
File file = new File(mailTpl);
mailHtml = FileUtil.readAsString(file);
mailHtml = mailHtml.replace("[MAIL_SUBJECT]", "문의글 답변 승인 부탁드립니다.");
mailHtml = mailHtml.replace("[MAIL_CONT]", "답변 승인 부탁드립니다.");
emailSender.send("kgalam@nate.com", mailSubject, mailHtml);*/
        return "";
}

'Skill > spring' 카테고리의 다른 글

MyBatis <selectKey>를 사용하여 SEQUENCE 값을 가져오기  (0) 2025.03.28
Invalid CSRF token found 오류 해결 방법  (0) 2025.03.20
Query Timeout 적용 최종  (0) 2025.01.13
SMTPConfig.java  (0) 2025.01.13
ServiceInitializer.java  (0) 2025.01.13
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함