From 45d41cfd1896f678ba476ecf71c378f41245d3eb Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 3 Jul 2017 18:45:05 +0900 Subject: [PATCH] email attach send method added --- pom.xml | 22 +++++++++++++++++ .../email/service/EmailAuthService.java | 24 +++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6451413..866e1b2 100644 --- a/pom.xml +++ b/pom.xml @@ -173,6 +173,28 @@ + + cz.habarta.typescript-generator + typescript-generator-maven-plugin + 1.25.322 + + + generate + + generate + + process-classes + + + + jackson2 + + com.loafle.overflow.module.**.model.* + + module + implementationFile + + diff --git a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java index 1f1c33b..c52bc2e 100644 --- a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java +++ b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java @@ -4,11 +4,16 @@ import com.loafle.overflow.module.email.dao.EmailAuthDAO; import com.loafle.overflow.module.email.model.EmailAuth; import com.loafle.overflow.module.member.model.Member; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.FileSystemResource; import org.springframework.mail.MailException; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Service; +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import java.io.File; import java.util.List; /** @@ -25,7 +30,7 @@ public class EmailAuthService { public EmailAuth sendEmailByMemberId(long memberId, String memberEmail) { try { - this.sendEmail(memberEmail, "Test Spring Mail", "Confirm Email"); + this.sendSimpleEmail(memberEmail, "Test Spring Mail", "Confirm Email"); }catch (MailException e) { e.printStackTrace(); } @@ -56,7 +61,7 @@ public class EmailAuthService { return this.emailAuthDAO.save(emailAuth); } - public void sendEmail(String to, String sub, String message) throws MailException { + public void sendSimpleEmail(String to, String sub, String message) throws MailException { SimpleMailMessage message1 = new SimpleMailMessage(); message1.setTo(to); @@ -66,4 +71,19 @@ public class EmailAuthService { mailSender.send(message1); } + + public void sendMailWithAttachment(String to, String sub, String text, String path) throws MessagingException { + MimeMessage message = mailSender.createMimeMessage(); + // pass 'true' to the constructor to create a multipart message + MimeMessageHelper helper = new MimeMessageHelper(message, true); + + helper.setTo(to); + helper.setSubject(sub); + helper.setText(text); + helper.setFrom("geek@loafle.com"); + FileSystemResource file = new FileSystemResource(new File(path)); + helper.addAttachment("Invoice", file); + + mailSender.send(message); + } }