[Spring][쇼핑몰 프로젝트][4] 인증번호 이메일 전송(1)

1. 이메일 전송 환경 세팅

2. 인증번호 입력란 색상 변경 및 disabled 속성 추가

3. 이메일 전송 메서드 추가(자바스크립트)

4. Controller 메서드 추가

5. 테스트
This commit is contained in:
SeoJin Kim
2020-11-02 21:15:48 +09:00
parent 7f293a6cee
commit 9fe7518bc0
14 changed files with 172 additions and 8 deletions

View File

@@ -164,7 +164,21 @@
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4</artifactId>
<version>1.16</version>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Servlet -->
<!-- <dependency>

View File

@@ -76,4 +76,17 @@ public class MemberController {
} // memberIdChkPOST() 종료
/* 이메일 인증 */
@RequestMapping(value="/mailCheck", method=RequestMethod.GET)
@ResponseBody
public void mailCheckGET(String email) throws Exception{
/* 뷰(View)로부터 넘어온 데이터 확인 */
logger.info("이메일 데이터 전송 확인");
logger.info("인증번호 : " + email);
}
}

View File

@@ -24,6 +24,26 @@
<property name="dataSource" ref="datasource"></property>
</bean>
<!-- navermail설정 -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.naver.com"/> <!-- 메이서버 호스트 -->
<property name="port" value="465"/> <!-- 메이서버 포트번호 -->
<property name="username" value="your_email"/> <!-- 자신의 이메일 아이디 -->
<property name="password" value="your_password"/> <!-- 자신의 비밀번호 -->
<!-- 보안연결 SSL과 관련된 설정 -->
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtps.checkserveridentity">true</prop>
<prop key="mail.smtps.ssl.trust">*</prop>
<prop key="mail.debug">true</prop>
<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
</props>
</property>
</bean>
<context:component-scan base-package="com.vam.sample"></context:component-scan>
<mybatis-spring:scan base-package="com.vam.mapper"/>

View File

@@ -51,8 +51,8 @@
<input class="mail_input" name="memberMail">
</div>
<div class="mail_check_wrap">
<div class="mail_check_input_box">
<input class="mail_check_input">
<div class="mail_check_input_box" id="mail_check_input_box_false">
<input class="mail_check_input" disabled="disabled">
</div>
<div class="mail_check_button">
<span>인증번호 전송</span>
@@ -125,6 +125,21 @@ $('.id_input').on("propertychange change keyup paste input", function(){
});// function 종료
/* 인증번호 이메일 전송 */
$(".mail_check_button").click(function(){
var email = $(".mail_input").val(); // 입력한 이메일
$.ajax({
type:"GET",
url:"mailCheck?email=" + email
});
});
</script>
</body>

View File

@@ -156,6 +156,12 @@
width: 61%;
float: left;
}
#mail_check_input_box_false{
background-color:#ebebe4;
}
#mail_check_input_box_true{
background-color:white;
}
.mail_check_input{
width:100%;
height:100%;

View File

@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Mon Aug 24 22:24:15 KST 2020
#Mon Nov 02 21:12:33 KST 2020
version=1.0.0-BUILD-SNAPSHOT
groupId=com.vam
m2e.projectName=VamPa

View File

@@ -164,7 +164,21 @@
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4</artifactId>
<version>1.16</version>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Servlet -->
<!-- <dependency>

View File

@@ -166,6 +166,20 @@
<version>1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Servlet -->
<!-- <dependency>
<groupId>javax.servlet</groupId>

View File

@@ -76,4 +76,16 @@ public class MemberController {
} // memberIdChkPOST() 종료
/* 이메일 인증 */
@RequestMapping(value="/mailCheck", method=RequestMethod.GET)
@ResponseBody
public void mailCheckGET(String email) throws Exception{
/* 뷰(View)로부터 넘어온 데이터 확인 */
logger.info("이메일 데이터 전송 확인");
logger.info("인증번호 : " + email);
}
}

View File

@@ -24,6 +24,25 @@
<property name="dataSource" ref="datasource"></property>
</bean>
<!-- navermail설정 -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.naver.com"/> <!-- 메이서버 호스트 -->
<property name="port" value="465"/> <!-- 메이서버 포트번호 -->
<property name="username" value="your_email"/> <!-- 자신의 이메일 아이디 -->
<property name="password" value="your_password"/> <!-- 자신의 비밀번호 -->
<!-- 보안연결 SSL과 관련된 설정 -->
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtps.checkserveridentity">true</prop>
<prop key="mail.smtps.ssl.trust">*</prop>
<prop key="mail.debug">true</prop>
<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
</props>
</property>
</bean>
<context:component-scan base-package="com.vam.sample"></context:component-scan>
<mybatis-spring:scan base-package="com.vam.mapper"/>

View File

@@ -51,8 +51,8 @@
<input class="mail_input" name="memberMail">
</div>
<div class="mail_check_wrap">
<div class="mail_check_input_box">
<input class="mail_check_input">
<div class="mail_check_input_box" id="mail_check_input_box_false">
<input class="mail_check_input" disabled="disabled">
</div>
<div class="mail_check_button">
<span>인증번호 전송</span>
@@ -125,6 +125,23 @@ $('.id_input').on("propertychange change keyup paste input", function(){
});// function 종료
/* 인증번호 이메일 전송 */
$(".mail_check_button").click(function(){
var email = $(".mail_input").val(); // 입력한 이메일
$.ajax({
type:"GET",
url:"mailCheck?email=" + email
});
});
</script>
</body>

View File

@@ -156,6 +156,12 @@
width: 61%;
float: left;
}
#mail_check_input_box_false{
background-color:#ebebe4;
}
#mail_check_input_box_true{
background-color:white;
}
.mail_check_input{
width:100%;
height:100%;

View File

@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Mon Aug 24 22:24:15 KST 2020
#Mon Nov 02 21:12:34 KST 2020
version=1.0.0-BUILD-SNAPSHOT
groupId=com.vam
m2e.projectName=VamPa_MySQL

View File

@@ -166,6 +166,20 @@
<version>1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Servlet -->
<!-- <dependency>
<groupId>javax.servlet</groupId>