본문 바로가기
CLASS/기타

mail 보내기

by hingu 2024. 7. 5.

SMTP 서버 - POP3, IMAP3

=> 도메인 필수 (localhost, 127.0.0.1 , IP 주소 불능)

 

도메인 : 화이트도메인 - SPF로 서버에 등록시 100% 메일을 송수신

 

* IMAP - 메일 수신받을 경우 PC에 저장됨(단, 서버에도 정보가 저장됨) , 가장 많이 사용

* POP3 - 메일 수신받을 경우 PC에 저장됨  (단, 서버에는 저장하지 않음)

* SMTP - 메일을 발송하는 서버


 

nate.com 메일 -> 환경설정  ->  IMAP/SMTP , POP3/SMTP 사용여부 - 사용할거 사용 체크 (naver도 동일)

 

메일서버 (기본정보-host,port번호) 메모

smtp.mail.nate.com    587

imap.nate.com    993

 

mvnrepository.com 에서

JavaMail API (compat) » 1.4.7 다운 (.jar 파일)

buildpath-> config buildpath 에서 해당 .jar 파일 jump (classpath로 추가할것!)

 

java11번일 경우 라이브러리 한개 더 필요함

javax.activation 검색 -> 

JavaBeans(TM) Activation Framework » 1.1.1 다운 (.jar)

동일하게 jump 하세욤

⚡ 메일 발송(IMAP) - nate 메일로 전송할거임

- qamail.jsp
<form id="frm">
고객명 : <input type="text" name="ename"><br>
이메일 : <input type="text" name="fromemail"><br>
패스워드 : <input type="text" name="epass"><br>
문의제목 : <input type="text" name="subject"><br>
문의내용 : <br><textarea name="mailtext" rows="15" cols="40"></textarea><br>
<input type="button" value="문의하기" onclick="mail_post()">
</form>
</body>

<script type="text/javascript">
function mail_post(){
	frm.method="post";
	frm.action="./qamailok.do";
	frm.submit();
}
</script>



- qamailok.java (servlet 파일)

@WebServlet("/qamailok.do")
public class qamailok extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		String ename = request.getParameter("ename");
		String fromemail = request.getParameter("fromemail");
		String epass = request.getParameter("epass");
		String subject = request.getParameter("subject");
		String mailtext = request.getParameter("mailtext");
		
		//메일서버 (기본정보)
		String host = "smtp.mail.nate.com"; 
		String login_user = ""; //실제 로그인 아이디
		String login_pass = ""; //실제 로그인 비번
		String to_mail = ""; //도착하는 실제 메일주소 작성
		
		//네일서버 SMTP 셋팅 설정값
		Properties pp = new Properties();
		pp.put("mail.smtp.host", host); //메일서버 도메인 주소-이방법은 실제 잘 쓰진 않음 
		pp.put("mail.smtp.port", 587); //메일서버 전송 port번호
		pp.put("mail.smtp.auth", "true"); //로그인에 대한 암호화 사용
		pp.put("mail.smtp.debug", "true"); //메일 회신 주소가 잘못되어 반송되는 사항
		pp.put("mail.smtp.socketFactory.port", 587); //메일 발송에 대한 소켓포트통신
		
		//TLS : 전송 통신 보안 정책
		pp.put("mail.smtp.ssl.protocals", "TLSv1.2");
		
		Session ss = Session.getDefaultInstance(pp, new Authenticator() {
			@Override
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(login_user, login_pass);
			}
		});
		
		try {
			MimeMessage msg = new MimeMessage(ss);
			//보내는 사람의 정보 (이메일,이름)
			msg.setFrom(new InternetAddress(fromemail,ename));
			//받는 사람의 정보
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to_mail));
			msg.setSubject(subject); //메일 제목
			msg.setText(mailtext); //메일 내용
			Transport.send(msg); //메일 발송
			
			//최종 결과값 출력
			PrintWriter pw = response.getWriter();
			pw.write("<script>"
					+ "alert('메일 발송이 정상적으로 되었습니다.');"
					+ "locaton.href = './qamail.jsp';"
					+ "</script>");
			pw.close();
		}catch(Exception e) {
			System.out.println("메일발송 실패!!");
		}
	}
}


properties는 여기서..첨 써봄..  https://dev-eunse.tistory.com/189

session - 해당 라이브러리 사용




❓ TLS(Transport Layer Security) : 전송 통신 보안 정책
인터넷 상의 커뮤니케이션을 위한 개인 정보와 데이터 보안을 용이하게 하기 위해 설계되어 널리 채택된 보안 프로토콜

SHA-1 암호화 => TLS 1.0
SHA-2 암호화  => TLS 1.2
SHA-3 암호화  => TLS 1.3
암호화로 보내고 , 암호화로 받기 때문에 TLS로 전송

nate에서 1.2라서 (우리나란 거의 1.2 naver,nate.. , google은 1.3임)

❓ MIME : 인터넷 프로토콜 서비스 HTTP로 서로 통신하는 전자우편
미메..

 

🔽

요렇게 발송시
네이트 메일에서 요렇게 확인이 가능하다!

'CLASS > 기타' 카테고리의 다른 글

외부 페이지 팝업 결과값 CORS 해결법  (0) 2024.07.17
인증메일 보내기  (1) 2024.07.05
project 배포  (0) 2024.07.04
👀⚡  (0) 2024.06.27
게시판 editor api 설치 [ ckeditor4 ]  (0) 2024.06.17