상세 컨텐츠

본문 제목

이메일

스프링

by e7e 2022. 5. 13. 00:08

본문

SimpleMailMessage, MimeMessage, MimeMessageHelper
인증번호 방식(Cookie이용)
인증링크(URL)방식(DB이용)

pom.xml

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>${org.springframework-version}</version>
		</dependency>
 
		<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
		<dependency>
			<groupId>javax.mail</groupId>
			<artifactId>mail</artifactId>
			<version>1.4.7</version>
		</dependency>

메일서버의 환경설정에서 연결이 가능토록 먼저 설정을 해줘야 함
일반적으로 POP/IMAP을 사용한다고 설정해주면 됨.

Daum, Naver, Google 설정법만

	<bean id="mailSender2"
		class="org.springframework.mail.javamail.JavaMailSenderImpl">
		<property name="host" value="smtp.daum.net" />
		<property name="port" value="465" />
		<property name="username" value="아이디만" />
		<property name="password" value="암호" />
		<property name="javaMailProperties">
			<props>
				<prop key="mail.smtp.auth">true</prop>
				<!-- <prop key="mail.smtp.starttls.enable">true</prop> --> <!-- log확인시   없어도 됨 -->
				<prop key="mail.smtps.ssl.checkserveridentity">true</prop> <!--HELO or EHLO 사용 -->
				<!-- <prop key="mail.smtps.ssl.trust">*</prop> -->
				<prop key="mail.debug">true</prop>               <!-- 메일서버 접속내용 로그 출력 -->
				<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop> <!-- SSL 사용 -->
			</props>
		</property>
	</bean>
	<bean id="mailSender3"
		class="org.springframework.mail.javamail.JavaMailSenderImpl">
		<property name="host" value="smtp.naver.com" />
		<property name="port" value="465" />
		<property name="username" value="아이디만" />
		<property name="password" value="암호" />
		<property name="javaMailProperties">
			<props>
				<prop key="mail.smtp.auth">true</prop>
				<!--  <prop key="mail.smtp.starttls.enable">true</prop> --> <!-- SSL 사용시 없어도 됨 -->
				<prop key="mail.smtps.ssl.checkserveridentity">true</prop> <!--HELO or EHLO 사용 -->
				<!--  <prop key="mail.smtps.ssl.trust">*</prop> -->
				<prop key="mail.debug">true</prop>               <!-- 메일서버 접속내용 로그 출력 -->
				<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop> <!-- SSL 사용 -->
			</props>
		</property>
	</bean>
        <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
              <property name="host" value="smtp.gmail.com" />
              <property name="port" value="587" />
              <property name="username" value="아이디@gmail.com" />
              <property name="password" value="암호" />
              <property name="javaMailProperties">
                <props>
                    <prop key="mail.smtp.auth">true</prop>
                    <prop key="mail.smtp.starttls.enable">true</prop>
              </props>
             </property>
       </bean>

따라해보장 

https://dlgkstjq623.tistory.com/287

'스프링' 카테고리의 다른 글

Security AJAX  (2) 2022.05.23
Validator  (0) 2022.05.23
Transaction  (4) 2022.05.12
SQL로그 남기기(log4jdbc-log4j2)  (4) 2022.05.10
작은 재미 오픈API  (7) 2022.05.10

관련글 더보기