HrmSendMail.jsp
16.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<%@ page import="weaver.general.Util,
java.sql.Timestamp" %>
<jsp:useBean id="SendMail" class="weaver.general.SendMail" scope="page" />
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="JobTitlesComInfo1" class="weaver.hrm.job.JobTitlesComInfo" scope="page" />
<jsp:useBean id="JobGroupsComInfo1" class="weaver.hrm.job.JobGroupsComInfo" scope="page" />
<jsp:useBean id="JobActivitiesComInfo1" class="weaver.hrm.job.JobActivitiesComInfo" scope="page" />
<jsp:useBean id="CostCenterComInfo1" class="weaver.hrm.company.CostCenterComInfo" scope="page" />
<jsp:useBean id="ResourceComInfo1" class="weaver.hrm.resource.ResourceComInfo" scope="page" />
<jsp:useBean id="DepartmentComInfo1" class="weaver.hrm.company.DepartmentComInfo" scope="page" />
<jsp:useBean id="ContacterTitleComInfo1" class="weaver.crm.Maint.ContacterTitleComInfo" scope="page" />
<jsp:useBean id="SystemComInfo" class="weaver.system.SystemComInfo" scope="page" />
<jsp:useBean id="hr" class="java.util.Hashtable" scope="page" />
<jsp:useBean id="HrmSearchComInfo" class="weaver.hrm.search.HrmSearchComInfo" scope="session" />
<%@ page language="java" contentType="text/html; charset=UTF-8" %> <%@ include file="/systeminfo/init_wev8.jsp" %>
<%
int id= Util.getIntValue(request.getParameter("id"),0);
//modified by wcd 2014-07-04 [支持邮件发送多个应聘人]
String applyid=Util.null2String(request.getParameter("applyid"));
String issearch = Util.null2String(request.getParameter("issearch"));
String rid = Util.null2String(request.getParameter("rid"));
int pagenum=Util.getIntValue(request.getParameter("pagenum"),0); //对员发群件时
String fromPage = Util.null2String(request.getParameter("fromPage")).trim();
int mailid= Util.getIntValue(request.getParameter("mailid"),0);//获得版式id
String selfComment=Util.fromScreen(request.getParameter("selfComment"),user.getLanguage());//用户自输入邮件正文内容
String subject = Util.null2String(request.getParameter("subject"));//邮件subject
String from = Util.null2String(request.getParameter("from")); //发件人地址
//add by wjy
String nothrmids = Util.null2String(request.getParameter("nothrmids")); //经过选择排除的邮件发送人
String sqlwhere = Util.null2String(request.getParameter("sqlwhere"));
String fromdate = Util.null2String(request.getParameter("fromdate"));
String fromtime = Util.null2String(request.getParameter("fromtime"));
Date newdate = new Date() ;
long datetime = newdate.getTime() ;
Timestamp timestamp = new Timestamp(datetime) ;
String CurrentDate = (timestamp.toString()).substring(0,4) + "-" + (timestamp.toString()).substring(5,7) + "-" +(timestamp.toString()).substring(8,10);
String CurrentTime = (timestamp.toString()).substring(11,13) + ":" + (timestamp.toString()).substring(14,16) + ":" +(timestamp.toString()).substring(17,19);
fromdate = (fromdate.equals("")?CurrentDate:fromdate); //计划发送日期,如果不写则按当前日期
fromtime = (fromtime.equals("")?CurrentTime:fromtime); //计划发送时间,如果不写则按当前时间
//add end by wjy
// 对群发邮件进行改进, 增加了群发邮件认证部分的工作
String defmailserver = SystemComInfo.getDefmailserver() ;
String defneedauth = SystemComInfo.getDefneedauth() ;
String defmailuser = SystemComInfo.getDefmailuser() ;
String defmailpassword = SystemComInfo.getDefmailpassword() ;
SendMail.setMailServer(defmailserver) ;
if( defneedauth.equals("1") ) {
SendMail.setNeedauthsend(true) ;
SendMail.setUsername(defmailuser) ;
SendMail.setPassword(defmailpassword) ;
}
else SendMail.setNeedauthsend(false) ;
// 对群发邮件进行改进结束
String email = "" ;
String to = "" ;
String cc = "" ;
String bcc = "" ;
int char_set = 3 ;
String priority = "3" ;
String tempto = "";
String tempto2 = "";
String nothrmid = ""; //被排除的邮件发送人
String nextpageur1 = "" ;
String succeed = "" ;
/* 分为用户自输入邮件正文和采用版式两种方式,每种方式要虑到来自不同的4种情况*/
boolean sendok = false;
if(mailid==0) { //不采用版式时而在文本框输入信件内容的情况
if(issearch.equals("1") && applyid.length()==0) { //对某类员工发邮件
nextpageur1="/hrm/HrmTab.jsp?_fromURL=HrmResourceSearchResult&hassql=1";
if(!rid.equals(""))
rs.executeSql("select email,id from HrmResource where id in ("+rid+")");
else
rs.executeSql("select email,id from HrmResource "+HrmSearchComInfo.FormatSQLSearch());
int i=0 ;
to = "" ;
String body = selfComment ;
int temId = SendMail.sendhtmlMain(from,cc,bcc,char_set,priority,user,fromdate,fromtime,"1") ;
while(rs.next()){
tempto = Util.null2String(rs.getString(1)) ;
nothrmid = Util.null2String(rs.getString(2)) ;
if(nothrmids.indexOf(nothrmid)!=-1){
continue;
}
if( !tempto.equals("") && Util.isEmail(tempto)){
to = tempto;
sendok = SendMail.sendhtmlProxy(temId,to,Util.fromScreen2(subject,user.getLanguage()),body,nothrmid) ;
}
}
response.sendRedirect("HrmMailMerge.jsp?isclose=1");
return;
}
else if(id!=0&&id!=(-1)) { //对某个员工发邮件
nextpageur1="/hrm/HrmTab.jsp?_fromURL=HrmResource&id="+id;
rs.executeSql("select email,id from HrmResource where id="+id);
if(rs.next()) {
tempto = Util.null2String(rs.getString(1)) ;
tempto2 = Util.null2String(rs.getString(2)) ;
}
if( !tempto.equals("") && Util.isEmail(tempto)) to = tempto;
if(to.length()!=0) {
String body = selfComment ;
int temId = SendMail.sendhtmlMain(from,cc,bcc,char_set,priority,user,fromdate,fromtime,"1") ;
sendok = SendMail.sendhtmlProxy(temId,to,Util.fromScreen2(subject,user.getLanguage()),body,tempto2) ;
succeed = to ;
}
}
else if(applyid.length() > 0) { //对某个应聘者发邮件
nextpageur1="/hrm/career/HrmCareerApplyEdit.jsp?applyid="+applyid;
rs.executeSql("select email,id from HrmCareerApply where id in ("+applyid+")");
String body = selfComment ;
while(rs.next()) {
tempto = Util.null2String(rs.getString(1)) ;
tempto2 = Util.null2String(rs.getString(2)) ;
if( !tempto.equals("") && Util.isEmail(tempto)){
to = tempto;
}
if(to.length()!=0) {
int temId = SendMail.sendhtmlMain(from,cc,bcc,char_set,priority,user,fromdate,fromtime,"2") ;
sendok = SendMail.sendhtmlProxy(temId,to,Util.fromScreen2(subject,user.getLanguage()),body,tempto2) ;
succeed = to ;
}
}
response.sendRedirect("HrmMailMerge.jsp?isclose=1");
return;
}
}
else { //采用版式时情况
if(issearch.equals("1") && applyid.length()==0) { //对某类员工发邮件
nextpageur1="/hrm/HrmTab.jsp?_fromURL=HrmResourceSearchResult&hassql=1";
String subject1 = subject;
String body = "";
String sql = "select mouldtext from DocMailMould where id="+mailid ;
rs.executeSql(sql);
if(rs.next()){
body = Util.null2String(rs.getString(1));
}
int pos = body.indexOf("<IMG alt=");
while(pos!=-1){
pos = body.indexOf("?fileid=",pos);
int endpos = body.indexOf("\"",pos);
String tmpid = body.substring(pos+8,endpos);
int startpos = body.lastIndexOf("\"",pos);
String servername = request.getServerName();
String tmpcontent = body.substring(0,startpos+1);
tmpcontent += "http://"+servername;
tmpcontent += body.substring(startpos+1);
body = tmpcontent;
pos = body.indexOf("<IMG alt=",endpos);
}
if(!rid.equals(""))
rs.executeSql("select * from HrmResource where id in ("+rid+")");
else
rs.executeSql("select * from HrmResource "+HrmSearchComInfo.FormatSQLSearch());
int temId = SendMail.sendhtmlMain(from,cc,bcc,char_set,priority,user,fromdate,fromtime,"1") ;
while(rs.next()){
tempto = Util.null2String(rs.getString("email")) ;
tempto2 = Util.null2String(rs.getString("id")) ;
if( !tempto.equals("") && Util.isEmail(tempto)) {
to = tempto ;
hr.put("HRM_Loginid",""+rs.getString("loginid"));
hr.put("HRM_Name",""+rs.getString("name"));
hr.put("HRM_Title",""+ContacterTitleComInfo1.getContacterTitlename(rs.getString("titleid")));
hr.put("HRM_Birthday",""+rs.getString("birthday"));
hr.put("HRM_Telephone",""+rs.getString("telephone"));
hr.put("HRM_Email",""+rs.getString("email"));
hr.put("HRM_Startdate",""+rs.getString("startdate"));
hr.put("HRM_Enddate",""+rs.getString("enddate"));
hr.put("HRM_Contractdate",""+rs.getString("contractdate"));
hr.put("HRM_Jobtitle",""+JobTitlesComInfo1.getJobTitlesname(rs.getString("jobtitle")));
hr.put("HRM_Jobgroup",""+JobGroupsComInfo1.getJobGroupsname(rs.getString("jobgroup")));
hr.put("HRM_Jobactivity",""+JobActivitiesComInfo1.getJobActivitiesname(rs.getString("jobactivity")));
hr.put("HRM_Jobactivitydesc",""+rs.getString("jobactivitydesc"));
hr.put("HRM_Joblevel",""+rs.getString("joblevel"));
hr.put("HRM_Seclevel",""+rs.getString("seclevel"));
hr.put("HRM_Department",""+DepartmentComInfo1.getDepartmentname(rs.getString("departmentid")));
hr.put("HRM_Costcenter",""+CostCenterComInfo1.getCostCentername(rs.getString("costcenterid")));
hr.put("HRM_Manager",""+ResourceComInfo1.getResourcename(rs.getString("managerid")));
hr.put("HRM_Assistant",""+ResourceComInfo1.getResourcename(rs.getString("assistantid")));
String tempbody = Util.toScreen(Util.fillValuesToString(body,hr),user.getLanguage()) ;
String tempsubject = Util.fromScreen2(Util.fillValuesToString(subject,hr),user.getLanguage());
sendok = SendMail.sendhtmlProxy(temId,to,Util.fromScreen2(subject,user.getLanguage()),body,tempto2) ;
succeed = succeed + to + "," ;
}
}
response.sendRedirect("HrmMailMerge.jsp?isclose=1");
return;
}
else if(id!=0&&id!=(-1)) { //对某个员工发邮件
nextpageur1="/hrm/HrmTab.jsp?_fromURL=HrmResource&id="+id;
rs.executeSql("select * from HrmResource where id="+id);
if(rs.next()) {
tempto = Util.null2String(rs.getString("email")) ;
tempto2 = Util.null2String(rs.getString("id")) ;
if( !tempto.equals("") && Util.isEmail(tempto)) {
to = tempto;
hr.put("HRM_Loginid",""+rs.getString("loginid"));
hr.put("HRM_Name",""+rs.getString("name"));
hr.put("HRM_Title",""+ContacterTitleComInfo1.getContacterTitlename(rs.getString("titleid")));
hr.put("HRM_Birthday",""+rs.getString("birthday"));
hr.put("HRM_Telephone",""+rs.getString("telephone"));
hr.put("HRM_Email",""+rs.getString("email"));
hr.put("HRM_Startdate",""+rs.getString("startdate"));
hr.put("HRM_Enddate",""+rs.getString("enddate"));
hr.put("HRM_Contractdate",""+rs.getString("contractdate"));
hr.put("HRM_Jobtitle",""+JobTitlesComInfo1.getJobTitlesname(rs.getString("jobtitle")));
hr.put("HRM_Jobgroup",""+JobGroupsComInfo1.getJobGroupsname(rs.getString("jobgroup")));
hr.put("HRM_Jobactivity",""+JobActivitiesComInfo1.getJobActivitiesname(rs.getString("jobactivity")));
hr.put("HRM_Jobactivitydesc",""+rs.getString("jobactivitydesc"));
hr.put("HRM_Joblevel",""+rs.getString("joblevel"));
hr.put("HRM_Seclevel",""+rs.getString("seclevel"));
hr.put("HRM_Department",""+DepartmentComInfo1.getDepartmentname(rs.getString("departmentid")));
hr.put("HRM_Costcenter",""+CostCenterComInfo1.getCostCentername(rs.getString("costcenterid")));
hr.put("HRM_Manager",""+ResourceComInfo1.getResourcename(rs.getString("managerid")));
hr.put("HRM_Assistant",""+ResourceComInfo1.getResourcename(rs.getString("assistantid")));
String sql = "select mouldtext from DocMailMould where id="+mailid;
String body = "";
rs.executeSql(sql);
if(rs.next()){
body = Util.null2String(rs.getString(1));
}
int pos = body.indexOf("<IMG alt=");
while(pos!=-1){
pos = body.indexOf("?fileid=",pos);
int endpos = body.indexOf("\"",pos);
String tmpid = body.substring(pos+8,endpos);
int startpos = body.lastIndexOf("\"",pos);
String servername = request.getServerName();
String tmpcontent = body.substring(0,startpos+1);
tmpcontent += "http://"+servername;
tmpcontent += body.substring(startpos+1);
body=tmpcontent;
pos = body.indexOf("<IMG alt=",endpos);
}
subject = Util.fromScreen2(Util.fillValuesToString(subject,hr),user.getLanguage());
body = Util.toScreen(Util.fillValuesToString(body,hr),user.getLanguage());
int temId = SendMail.sendhtmlMain(from,cc,bcc,char_set,priority,user,fromdate,fromtime,"1") ;
sendok = SendMail.sendhtmlProxy(temId,to,Util.fromScreen2(subject,user.getLanguage()),body,tempto2) ;
succeed = to ;
}
}
}
else if(applyid.length() > 0) { //对某个应聘者发邮件
nextpageur1="/hrm/career/HrmCareerApplyEdit.jsp?applyid="+applyid;
rs.executeSql("select email,id from HrmCareerApply where id="+applyid);
if(rs.next()) {
tempto = Util.null2String(rs.getString(1)) ;
tempto2 = Util.null2String(rs.getString(2)) ;
}
if( !tempto.equals("") && Util.isEmail(tempto)) to = tempto;
if(to.length()!=0) {
String sql = "select mouldtext from DocMailMould where id="+mailid;
String body = "";
rs.executeSql(sql);
if(rs.next()){
body = Util.null2String(rs.getString(1));
}
int pos = body.indexOf("<IMG alt=");
while(pos!=-1){
pos = body.indexOf("?fileid=",pos);
int endpos = body.indexOf("\"",pos);
String tmpid = body.substring(pos+8,endpos);
int startpos = body.lastIndexOf("\"",pos);
String servername = request.getServerName();
String tmpcontent = body.substring(0,startpos+1);
tmpcontent += "http://"+servername;
tmpcontent += body.substring(startpos+1);
body=tmpcontent;
pos = body.indexOf("<IMG alt=",endpos);
}
rs.executeProc("HrmCareerApply_SelectById",""+applyid);
rs.next();
hr.put("HRM_Email",""+rs.getString("email"));
subject = Util.fromScreen2(Util.fillValuesToString(subject,hr),user.getLanguage());
body = Util.toScreen(Util.fillValuesToString(body,hr),user.getLanguage()) ;
int temId = SendMail.sendhtmlMain(from,cc,bcc,char_set,priority,user,fromdate,fromtime,"2") ;
sendok = SendMail.sendhtmlProxy(temId,to,Util.fromScreen2(subject,user.getLanguage()),body,tempto2) ;
succeed = to ;
}
response.sendRedirect("HrmMailMerge.jsp?isclose=1");
return;
}
}
if(!succeed.equals("")) succeed = succeed.substring(0,succeed.length()-1);
boolean gotoWindowParent = (id!=0&&id!=(-1));
if (sendok) {
%>
<script>
//alert("系统提示:<%=succeed%>邮件发送成功!");
if(<%=gotoWindowParent%> && <%=fromPage.length()>0%>){
window.location = decodeURIComponent("<%=fromPage%>");
}else{
//window.location = "<%=nextpageur1%>";
window.close();
}
</script>
<%
} else {
%>
<script>
//alert("系统提示:<%=succeed%>邮件发送失败!");
if(<%=gotoWindowParent%> && <%=fromPage.length()>0%>){
window.location = decodeURIComponent("<%=fromPage%>");
}else{
//window.location = "<%=nextpageur1%>";
window.close();
}
</script>
<%
}
%>