email attach send method added

This commit is contained in:
geek 2017-07-03 18:45:05 +09:00
parent b7d0ac08cf
commit 45d41cfd18
2 changed files with 44 additions and 2 deletions

22
pom.xml
View File

@ -173,6 +173,28 @@
</dependencies>
</plugin>
<plugin>
<groupId>cz.habarta.typescript-generator</groupId>
<artifactId>typescript-generator-maven-plugin</artifactId>
<version>1.25.322</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
<configuration>
<jsonLibrary>jackson2</jsonLibrary>
<classPatterns>
<classPattern>com.loafle.overflow.module.**.model.*</classPattern>
</classPatterns>
<outputKind>module</outputKind>
<outputFileType>implementationFile</outputFileType>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -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);
}
}