Skip to content

Commit

Permalink
feat : 이메일 꾸미기 + 배포용 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
Doncham committed Mar 19, 2024
1 parent babf407 commit 81d821e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.Backend.shareNote.domain.EmailService;

import jakarta.mail.internet.MimeMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

Expand All @@ -19,21 +21,54 @@ public class EmailService {
private final JavaMailSender javaMailSender;
@Async
public boolean sendMail(EmailDTO emailDTO) {
boolean msg = false;
SimpleMailMessage message = new SimpleMailMessage();
log.info("이메일 어디로 갔을까?? : " + emailDTO.getTargetMail());
message.setTo(emailDTO.getTargetMail());
message.setSubject("너 내 동료가 돼라");
message.setFrom(mailProperties.getUsername());
message.setText("너 이 링크를 누르고 내 동료가 돼라!! from " +emailDTO.getNickname() + " " + emailDTO.getLink());

try {
javaMailSender.send(message);
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, "utf-8");

helper.setTo(emailDTO.getTargetMail());
helper.setSubject("sharenote 초대장");
helper.setFrom("your-email@example.com"); // 이메일 발신자 주소
String htmlMsg = """
<div style="font-family: 'Arial', sans-serif; color: #333;">
<h2>안녕하세요&nbsp; """ + emailDTO.getNickname() + """
님으로부터 도착한 초대장입니다.</h2>
<p>아래의 버튼을 눌러 노트를 작성해주세요!</p>
<div style="margin: 20px 0;">
<a href='""" + emailDTO.getLink() + """
' style="background-color: #4CAF50; color: white; padding: 14px 20px; text-align: center; text-decoration: none; display: inline-block; border-radius: 5px;">초대장</a>
</div>
</p>
</div>
""";

helper.setText(htmlMsg, true); // HTML 콘텐츠로 이메일 설정


javaMailSender.send(mimeMessage);
return true;
} catch (Exception e) {
e.printStackTrace();
return msg;
return false;
}
return msg = true;

}
}

// boolean msg = false;
// SimpleMailMessage message = new SimpleMailMessage();
// log.info("이메일 어디로 갔을까?? : " + emailDTO.getTargetMail());
// message.setTo(emailDTO.getTargetMail());
// message.setSubject("너 내 동료가 돼라");
// message.setFrom(mailProperties.getUsername());
// message.setText("너 이 링크를 누르고 내 동료가 돼라!! from " +emailDTO.getNickname() + " " + emailDTO.getLink());
//
// try {
// javaMailSender.send(message);
// } catch (Exception e) {
// e.printStackTrace();
// return msg;
// }
// return msg = true;

// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public ResponseEntity<Object> inviteOrganization(OrganizationInvitation invitati
//쿼리 파라미터로 동작
//이 링크 클릭 시 토큰을 localStorage에 저장하고
//login 시 토큰을 가져와서 organization 초대 수락하기
emailDTO.setLink("http://localhost:3000/organization/invitation/approve?token=" + Token);
//emailDTO.setLink("http://localhost:3000/organization/invitation/approve?token=" + Token);
emailDTO.setLink("http://sharenote.shop/organization/invitation/approve?token=" + Token);
emailService.sendMail(emailDTO);
return ResponseEntity.ok("초대장 전송 완료");
}
Expand Down

0 comments on commit 81d821e

Please sign in to comment.