๐ŸŒธ [SPRING BOOT] | ๐ŸŽฎ์ด๋ฉ”์ผ ๋ณด๋‚ด๊ธฐ ๊ธฐ๋Šฅ๊ณผ ์—๋Ÿฌ

2
post-thumbnail

๐Ÿ”น SimpleMailMessage.setFrom(from);

  • ๋นˆ์— ์•„์ด๋”” ์„ค์ •ํ•œ ๊ฒƒ์€ ๋‹จ์ˆœํžˆ smtp ์ธ์ฆ์„ ๋ฐ›๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ
  • ๋”ฐ๋ผ์„œ ๋ณด๋‚ด๋Š”์ด(setFrom())๋ฐ˜๋“œ์‹œ ํ•„์š”
  • ๋ณด๋‚ด๋Š”์ด์™€ ๋ฉ”์ผ์ฃผ์†Œ๋ฅผ ์ˆ˜์‹ ํ•˜๋Š”์ด๊ฐ€ ๋ณผ๋•Œ ๋ชจ๋‘ ํ‘œ๊ธฐ ๋˜๊ฒŒ ์›ํ•˜์‹ ๋‹ค๋ฉด ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
  • mailHelper.setFrom("๋ณด๋‚ด๋Š”์ด ์ด๋ฆ„ <๋ณด๋‚ด๋Š”์ด ์•„์ด๋””@๋„๋ฉ”์ธ์ฃผ์†Œ>");

๐Ÿ”น SMTPSendFailedException

โœ… ์—๋Ÿฌ๋ฉ”์‹œ์ง€

org.springframework.mail.MailSendException: 
Failed messages: 
com.sun.mail.smtp.SMTPSendFailedException: 
530 5.7.0 Must issue a STARTTLS command first. 
m1sm11845126pjk.35 - gsmtp

โœ… ์›์ธ

  • yaml ์˜คํƒ€
  • stmp ๐Ÿ‘‰ smtp

์Šคํฌ๋ฆฐ์ƒท(38)

๐Ÿ”น No beans of 'JavaMailSender' type found.

โœ… ์—๋Ÿฌ๋ฉ”์‹œ์ง€

Field email in com.koreait.facebook.user.UserService 
required a bean of type 'com.koreait.facebook.common.EmailServiceImpl' 
that could not be found.

โœ… ์›์ธ

@Autowired
private JavaMailSender emailSender; 
  • ์—์„œ JavaMailSender๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์–ด์„œ ์—๋Ÿฌ๊ฐ€ ๋‚ฌ๋‹ค.

โœ… ํ•ด๊ฒฐ

  • yaml์— ์˜คํƒ€๋ฅผ ๋ฐ”๋กœ ์žก์•„์ฃผ๋ฉด ๋œ๋‹ค.

๐Ÿ”น EmailServiceImpl ํด๋ž˜์Šค์˜ sendMimeMessage ๋ฉ”์†Œ๋“œ

โœ… MimeMessageHelper mailHelper = new MimeMessageHelper(mail,true,"UTF-8");

  • MimeMessageHelper mailHelper = new MimeMessageHelper(mail,true,"UTF-8");
  • true๋Š” ๋ฉ€ํ‹ฐํŒŒํŠธ ๋ฉ”์„ธ์ง€๋ฅผ ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ
  • ๋ฉ€ํ‹ฐํŒŒํŠธ๊ฐ€ ํŒŒ์ผ์—…๋กœ๋“œ์—ฐ๊ด€๋œ๊ฒƒ์ด๋‹ค
  • falseํ•œ๋‹ค๋Š”๊ฑด ์•ˆ์“ด๋‹ค๋Š”๊ฑฐ๊ณ 
  • trueํ•˜๋ฉด ๋ฉ”์ผ๋ณด๋‚ผ๋•Œ ํŒŒ์ผ๋„ ๋ณด๋‚ผ์ˆ˜์žˆ๊ณ  ๊ทธ๋Ÿฐ ๊ฒƒ ๊ฐ™๋‹ค

โœ… MimeMessageHelper mailHelper = new MimeMessageHelper(mail,"UTF-8");

  • MimeMessageHelper mailHelper = new MimeMessageHelper(mail,"UTF-8");
  • ๋‹จ์ˆœํ•œ ํ…์ŠคํŠธ ๋ฉ”์„ธ์ง€๋งŒ ์‚ฌ์šฉ

โœ… mailHelper.setText(๋ณด๋‚ผ๋‚ด์šฉ, true);

  • mailHelper.setText(๋ณด๋‚ผ๋‚ด์šฉ, true);
  • true๋Š” html์„ ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.

โœ… mailHelper.setText(๋ณด๋‚ผ๋‚ด์šฉ);

  • ๋‹จ์ˆœํ•œ ํ…์ŠคํŠธ๋งŒ ์‚ฌ์šฉ

๐Ÿ”น MimeMessage์™€ MimeMessageHelper

        MimeMessage message = emailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, false, "UTF-8");
        helper.setFrom("goonturtle4u@gmail.com");
        helper.setSubject(subject);
        helper.setText(text, true);
        emailSender.send(message);

๐Ÿ”น SendFailedException

โœ… ์—๋Ÿฌ

  • ์ด๋ฉ”์ผ์„ mimeMessage๋กœ ๋ฐ”๊พผ ์ดํ›„๋กœ ๋ฉ”์„ธ์ง€๊ฐ€ ๊ฐ€์ง€ ์•Š๋Š”๋‹ค.

โœ… ์—๋Ÿฌ๋ฉ”์‹œ์ง€

Failed messages: 
javax.mail.SendFailedException: 
No recipient addresses
org.springframework.mail.MailSendException: 
Failed messages: 
javax.mail.SendFailedException: 
No recipient addresses; 
message exception details (1) are:
Failed message 1:

โœ… ์›์ธ & ํ•ด๊ฒฐ

  • ์›์ธ : ์˜คํƒ€
  • helper.setTo(to);๊ฐ€ ๋น ์กŒ๋‹ค.
        helper.setFrom("goonturtle4u@gmail.com");
        helper.setSubject(subject);
        helper.setText(text, true);        
                  ๐Ÿ‘‡
        helper.setFrom("goonturtle4u@gmail.com");
        helper.setTo(to);   โ›” ์ด๊ฑธ ๋นผ๋จน์Œ
        helper.setSubject(subject);
        helper.setText(text, true);
profile
๋ช‡ ๋ฒˆ์„ ๋„˜์–ด์ ธ๋„ ์•ž์œผ๋กœ ๊ณ„์† ๋‚˜์•„๊ฐ€์ž

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 4์›” 11์ผ

์ž˜ ๋ณด๊ณ  ๊ฐ‘๋‹ˆ๋‹ค ~~

๋‹ค๋งŒ ์ด๋ฉ”์ผ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ๋…ธ์ถœ๋˜์–ด ์žˆ์–ด์„œ ๊ฐ€๋ฆฌ์…”์•ผํ•  ๊ฒƒ ๊ฐ™์•„์š”~

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ