반응형
버전 정보
스프링 레거시 3.2.9.RELEASE
자바 1.8
javax.mail 1.6.2
maven 프로젝트
MailUtil.java
messageHelper.addInline("image", new ClassPathResource("/images/hanati/logo.png"));
아래는 전체 로직 코드입니다.
public boolean sendMail(Map msgInfo) throws Exception {
String subject = (String) msgInfo.get("p_mail_subject");//제목
String text = (String) msgInfo.get("p_mail_content");//내용
String fromUser = (String) msgInfo.get("p_send_email");//발신자 이메일
String fromUserName = (String) msgInfo.get("p_send_name");//발신자명
String toUser = (String) msgInfo.get("p_recv_email");//수신자 이메일
MimeMessage message = mailSender.createMimeMessage();
DataSource dataSource = null;
try {
MimeMessageHelper messageHelper = new MimeMessageHelper(message, true, SMTP_ENC);
messageHelper.setSubject(subject);
messageHelper.setTo(toUser);
messageHelper.setFrom(fromUser, StringUtil.nvl(fromUserName, fromUser));
messageHelper.setText(text, true);
messageHelper.addInline("image", new ClassPathResource("/images/hanati/logo.png"));
mailSender.send(message);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
HTML 그려주는 곳
sb.append("<img src='cid:image' title='이미지'/>");
messageHelper.addInline("원하는 명칭", new ClassPathResource("경로"));
<img src='cid:원하는 명칭'/>
위 두 값을 잘 맞추기만 하면 정상작동 합니다.
반응형
'프로그래밍 일기 > Java & Spring' 카테고리의 다른 글
Spring Boot Nuxt3 카카오 로그인 및 JWT 토큰 발급 (0) | 2024.07.22 |
---|---|
JWT란? (0) | 2024.07.09 |
[에러해결] javax.mail.MessagingException: Could not connect to SMTP host: smtp.worksmobile.com, port: 465, response: -1 (isSSL true 설정) (0) | 2023.07.18 |
[Spring Boot] 파일 다운로드 로직 구현 feat.Nuxt3 (0) | 2023.07.12 |
[Spring Boot] 단일, 다중 파일 업로드 로직 구현 feat.Nuxt3 (0) | 2023.07.12 |