163 lines
5.9 KiB
Plaintext
163 lines
5.9 KiB
Plaintext
<%@page import="java.util.Calendar"%>
|
|
<%@ page language="java" contentType="text/html; charset=utf-8"
|
|
pageEncoding="utf-8"%>
|
|
|
|
<%@ page trimDirectiveWhitespaces="true" %>
|
|
<%@ page import="javax.mail.Transport" %>
|
|
<%@ page import="javax.mail.Message" %>
|
|
<%@ page import="javax.mail.internet.InternetAddress" %>
|
|
<%@ page import="javax.mail.Address" %>
|
|
<%@ page import="javax.mail.internet.MimeMessage" %>
|
|
<%@ page import="javax.mail.Session" %>
|
|
<%@ page import="javax.mail.Authenticator" %>
|
|
<%@ page import="java.util.Properties" %>
|
|
<%@ page import="utility.SMTPAuthenticator" %>
|
|
<%@ page import="java.io.*"%>
|
|
<%@ page import="java.util.GregorianCalendar" %>
|
|
|
|
<%
|
|
String subject = request.getParameter("subject")==null?"":request.getParameter("subject");
|
|
String content = request.getParameter("content")==null?"":request.getParameter("content");
|
|
String from = request.getParameter("from")==null?"":request.getParameter("from"); //보내는 사람
|
|
String to = request.getParameter("to")==null?"":request.getParameter("to"); //받는 사람
|
|
String lo = request.getParameter("location");
|
|
String client_name = request.getParameter("client_name")==null?"":request.getParameter("client_name");//고객명
|
|
String service_code = request.getParameter("service_code")==null?"":request.getParameter("service_code");//service_code
|
|
if(from.equals("") || to.equals("") || content.equals("") || subject.equals("")){
|
|
{
|
|
System.out.println("메일 전송 실패");
|
|
String script="<script type='text/javascript'>\n";
|
|
script+="alert('메일발송에 실패했습니다.')\n";
|
|
script+="history.back();\n";
|
|
script+="</script>";
|
|
out.print(script);
|
|
}
|
|
}else{
|
|
// 프로퍼티 값 인스턴스 생성과 기본세션(SMTP 서버 호스트 지정)
|
|
//정보를 담기 위한 객체 생성
|
|
Properties props = new Properties();
|
|
|
|
/*
|
|
SMTP 서버의 계정설정
|
|
NAVER와 할 경우 smtp.naver.com
|
|
GOOGLE로 할 경우 smtp.gmail.com
|
|
*/
|
|
props.put("mail.smtp.host","smtp.gmail.com");//
|
|
//이하 props 정보는 수정하지 말것(구글 네이버 동일함)
|
|
props.put("mail.smtp.port", "465");//포트번호 설정(465)
|
|
props.put("mail.smtp.starttls.enable","true"); //뭔가 사용가능하도록 설정함
|
|
props.put("mail.smtp.auth","true");//위와 동
|
|
props.put("mail.smtp.debug","true");//디버그 기능 사용
|
|
props.put("mail.smtp.socketFactory.port","465");//socketFactory의 포트를 465로 설정
|
|
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");//socketFactory의 클래스 위치 설정
|
|
props.put("mail.smtp.socketFactory.fallback","false");//모르겠다.
|
|
//설정 끝
|
|
|
|
FileWriter fw=null;
|
|
|
|
try
|
|
{
|
|
Authenticator auth = new SMTPAuthenticator();
|
|
Session ses = Session.getInstance(props,auth);
|
|
|
|
//메일 전송시 상세한 상황을 콘솔에 출력한다.
|
|
ses.setDebug(true);
|
|
MimeMessage msg = new MimeMessage(ses);
|
|
|
|
//제목설정
|
|
subject = new String(subject.getBytes("8859_1"),"utf-8");
|
|
msg.setSubject(subject,"utf-8");
|
|
|
|
//보내는사람의 메일주소
|
|
Address fromAddr = new InternetAddress(from);
|
|
msg.setFrom(fromAddr);
|
|
|
|
//받는사람의 메일주소
|
|
Address toAddr = new InternetAddress(to);
|
|
msg.addRecipient(Message.RecipientType.TO, toAddr);
|
|
|
|
//메세지 본문의 내용과 형식, 캐릭터 셋 설정
|
|
String content2 = new String(content.getBytes("8859_1"),"utf-8");
|
|
msg.setHeader("content-type", "text/html; charset=utf-8");
|
|
msg.setContent(content2, "text/html; charset=utf-8");
|
|
Transport.send(msg);
|
|
|
|
/*메일저장*/
|
|
String loca = "";
|
|
if(lo.equals("IdcDepositNonPaymentList"))
|
|
loca="window.location='IdcDepositNonPaymentList.dep';\n";
|
|
else if(lo.equals("IdcReSendMailList"))
|
|
loca="window.location='IdcReSendMailList.dep';\n";
|
|
else if(lo.equals("bill"))
|
|
loca="history.go(-2);\n";
|
|
|
|
System.out.println("loca : " + loca);
|
|
System.out.println("lo : " + lo);
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
String saveDirectory = this.getClass().getResource("").getPath()+"../../../../../../../wtpwebapps/idcProject/SendMailFolder/";
|
|
saveDirectory = saveDirectory.replaceAll("%20", " ");
|
|
String gettime =cal.getTime().toString();
|
|
gettime = gettime.replaceAll(" ", "_");
|
|
gettime = gettime.replaceAll(":","_");
|
|
String client_name2 = new String(request.getParameter("client_name").getBytes("8859_1"),"utf-8");
|
|
String path = saveDirectory+"_"+client_name2+"_"+gettime+".txt";
|
|
|
|
fw = new FileWriter(path);
|
|
fw.write(content2);
|
|
|
|
String sendData = "service_code=" + service_code + "&client_name=" + client_name2 + "&filepath="+path;
|
|
String jso = "IdcSendMailSaveJSONCmd.jso";
|
|
|
|
|
|
String script ="<script src='IDC/js/jquery-2.1.3.min.js'></script>\n";
|
|
|
|
script+="<script type='text/javascript'>\n";
|
|
script+="$(function()\n{\n";
|
|
script+="$.get(\n";
|
|
script+="'IdcSendMailSaveJSONCmd.jso',\n";
|
|
script+="'"+sendData+"',function(data)\n";
|
|
script+="{\n";
|
|
script+="});\n})\n";
|
|
|
|
script+=loca;
|
|
script+="</script>";
|
|
out.print(script);
|
|
}
|
|
catch(Exception mex)
|
|
{
|
|
mex.printStackTrace();
|
|
String script="<script type='text/javascript'>\n";
|
|
script+="alert('메일발송에 실패했습니다.')\n";
|
|
script+="history.back();\n";
|
|
script+="</script>";
|
|
out.print(script);
|
|
return;
|
|
}
|
|
finally
|
|
{
|
|
fw.close();
|
|
//request.getSession().removeAttribute("content");
|
|
}
|
|
}
|
|
%>
|
|
|
|
<!--
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
|
|
<title>메일 보내기 TEST</title>
|
|
</head>
|
|
<body>
|
|
<form action="SendEmail.jsp">
|
|
제목 : <input type="text" width="20px" name="subject"/><br>
|
|
보내는 사람 : <input type="text" width="20px" name="from"/><br>
|
|
받는 사람 : <input type="text" width="20px" name="to"/><br>
|
|
내용<br>
|
|
<textarea rows="5" cols="30" name="content"></textarea>
|
|
<input type="submit" name="button" value="전송">
|
|
</form>
|
|
</body>
|
|
</html>
|
|
--> |