From da34f5932e1c7a8b129815a080576b4751bee57b Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 3 Jul 2017 15:03:00 +0900 Subject: [PATCH 1/3] EmailAuth Service method added --- .../email/service/EmailAuthService.java | 56 +++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) 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 69ba19f..1f1c33b 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 @@ -1,11 +1,16 @@ package com.loafle.overflow.module.email.service; +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.mail.MailException; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Service; +import java.util.List; + /** * Created by geek on 17. 6. 28. */ @@ -15,19 +20,50 @@ public class EmailAuthService { @Autowired private JavaMailSender mailSender; + @Autowired + private EmailAuthDAO emailAuthDAO; - public void sendEmail(String to, String sub, String message) { - + public EmailAuth sendEmailByMemberId(long memberId, String memberEmail) { try { - SimpleMailMessage message1 = new SimpleMailMessage(); - message1.setTo(to); - message1.setSubject(sub); - message1.setText(message); - message1.setFrom("geek@loafle.com"); - - mailSender.send(message1); - } catch (MailException e) { + this.sendEmail(memberEmail, "Test Spring Mail", "Confirm Email"); + }catch (MailException e) { e.printStackTrace(); } + + EmailAuth auth = new EmailAuth(); + auth.setMember(new Member(memberId)); + // Todo AuthKey Generation + auth.setEmailAuthKey("djdjdjdjeiejdikdjki"); + + this.emailAuthDAO.save(auth); + + return auth; + } + + public EmailAuth read(long id) { + return this.emailAuthDAO.findOne(id); + } + + public EmailAuth readByAuthKey(String authKey) { + return this.emailAuthDAO.findByEmailAuthKey(authKey); + } + + public List readByMember(long memberId) { + return this.emailAuthDAO.findByMember(new Member(memberId)); + } + + public EmailAuth modify(EmailAuth emailAuth) { + return this.emailAuthDAO.save(emailAuth); + } + + public void sendEmail(String to, String sub, String message) throws MailException { + + SimpleMailMessage message1 = new SimpleMailMessage(); + message1.setTo(to); + message1.setSubject(sub); + message1.setText(message); + message1.setFrom("geek@loafle.com"); + + mailSender.send(message1); } } From b7d0ac08cfc53d8f8155c744db5326328521faac Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 3 Jul 2017 15:21:01 +0900 Subject: [PATCH 2/3] EmailAuth Timestamp -> Date --- .../overflow/module/email/model/EmailAuth.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java b/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java index c46f672..83705fc 100644 --- a/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java +++ b/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java @@ -3,7 +3,7 @@ package com.loafle.overflow.module.email.model; import com.loafle.overflow.module.member.model.Member; import javax.persistence.*; -import java.sql.Timestamp; +import java.util.Date; /** * Created by root on 17. 6. 22. @@ -13,8 +13,8 @@ import java.sql.Timestamp; public class EmailAuth { private long id; private String emailAuthKey; - private Timestamp createDate; - private Timestamp authConfirmDate; + private Date createDate; + private Date authConfirmDate; private Member member; @Id @@ -39,21 +39,21 @@ public class EmailAuth { @Basic @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - public Timestamp getCreateDate() { + public Date getCreateDate() { return createDate; } - public void setCreateDate(Timestamp createDate) { + public void setCreateDate(Date createDate) { this.createDate = createDate; } @Basic @Column(name = "AUTH_CONFIRM_DATE", nullable = true, insertable = true, updatable = false) - public Timestamp getAuthConfirmDate() { + public Date getAuthConfirmDate() { return authConfirmDate; } - public void setAuthConfirmDate(Timestamp authConfirmDate) { + public void setAuthConfirmDate(Date authConfirmDate) { this.authConfirmDate = authConfirmDate; } From 45d41cfd1896f678ba476ecf71c378f41245d3eb Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 3 Jul 2017 18:45:05 +0900 Subject: [PATCH 3/3] 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); + } }