public class MailMail { private JavaMailSender mailSender; private SimpleMailMessage simpleMailMessage; public void setSimpleMailMessage(SimpleMailMessage simpleMailMessage) { this.simpleMailMessage = simpleMailMessage; } public void setMailSender(JavaMailSender mailSender) { this.mailSender = mailSender; } public void sendMail(String dear, String content) { MimeMessage message = mailSender.createMimeMessage(); try{ MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setFrom(simpleMailMessage.getFrom()); helper.setTo(simpleMailMessage.getTo()); helper.setSubject(simpleMailMessage.getSubject()); helper.setText(String.format( simpleMailMessage.getText(), dear, content)); FileSystemResource file = new FileSystemResource("C:\\log.txt"); helper.addAttachment(file.getFilename(), file); }catch (MessagingException e) { throw new MailParseException(e); } mailSender.send(message); } }
InputStream
은 ByteArrayDataSource
사용ByteArrayDataSource attachment = new ByteArrayDataSource(message.getPayload(), "application/octet-stream");
Passed-in Resource contains an open stream: invalid argument. JavaMail requires an InputStreamSource that creates a fresh stream for every call.
오류 발생