/* properties 설정 */
# Google Mail
mail.host=smtp.gmail.com
mail.port=587
mail.username=gongjetest@gmail.com
mail.password=gongje1234
mail.smtp.auth=true
mail.smtp.starttls.enable=true
=========================================================
/* context-mail.xml */
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${mail.host}" />
<property name="username" value="${mail.username}" />
<property name="password" value="${mail.password}" />
<property name="port" value="${mail.port}" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.starttls.enable">${mail.smtp.starttls.enable}</prop>
<prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
</props>
</property>
</bean>
</beans>
/* CommServiceImpl.java */
package sample.common.service.impl;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import khma.gongje.common.service.CommService;
import khma.gongje.common.service.EmailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
/**
* 공통정보 CRUD 요청을 처리하는 비즈니스 클래스
*
* @author 윤혁신
* @since 2015.01.19
* @version 1.0
* @see <pre>
* == 개정이력(Modification Information) ==
*
* 수정일 수정자 수정내용
* ---------------- ------------ ---------------------------
* 2014.01.19 윤혁신 최초 생성
*
* </pre>
*/
@Service
public class CommServiceImpl implements CommService {
@Autowired
private JavaMailSender mailSender;
/**
* 이메일 발송
* @param emailVO
* @throws Exception
*/
public void sendMail(EmailVO emailVO) throws Exception {
MimeMessage message = mailSender.createMimeMessage();
try {
MimeMessageHelper messageHelper = new MimeMessageHelper(message, true, "UTF-8");
messageHelper.setSubject(emailVO.getSubject());
messageHelper.setTo(emailVO.getSendTo());
if(emailVO.getSendCc() != null && !emailVO.getSendCc().equals("")) {
messageHelper.setCc(emailVO.getSendCc());
}
if(emailVO.getSendFrom() != null && !emailVO.getSendFrom().equals("")) {
messageHelper.setFrom(emailVO.getSendFrom());
}
messageHelper.setText(emailVO.getMailText(), true);
mailSender.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
댓글 없음:
댓글 쓰기