3c1d5cc4ca88867ee5f47abd43b3d5e65875e407.svn-base
9.3 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
package com.espeed.action;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.mail.Transport;
import com.espeed.centre.pojo.YxyUserInfo;
import com.espeed.log.LogClass;
import com.espeed.pojo.YxySendSmtpInfo;
import com.espeed.pojo.YxySmtpList;
import com.espeed.service.YxySendSmtpInfoService;
import com.espeed.tool.DES_Encrypt;
import com.opensymphony.xwork2.ActionContext;
/***
* SMTP信息action
*/
public class YxySendSmtpInfoAction extends BaseAction{
private static final long serialVersionUID = 1L;
/**查询用户SMTP信息*/
public String findAllSmtp(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
smtplist=yxysendsmtpinfoservice.findAllSmtp(loginid,domain);
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return "list";
}
/**查询SMTP List信息*/
public String findSmtpList(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
smtplistall=yxysendsmtpinfoservice.findAllList();
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return "smtplist";
}
/**添加/编辑SMTP信息*/
public String addSmtpInfo(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
//当前时间
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowDate=df.format(new Date());
yxysendsmtpinfo.setSmtp_user_domain(domain);
yxysendsmtpinfo.setSmtp_user_loginid(loginid);
yxysendsmtpinfo.setSmtp_service_creatdate(nowDate);
yxysendsmtpinfo.setSmtp_service_isuse(0);
yxysendsmtpinfo.setSmtp_service_sendNum(0);
yxysendsmtpinfo.setSmtp_service_userdate(nowDate);
//是营销还是自配
Map domaingraph=(Map) sess.get("domaingraph");
int isself=Integer.parseInt(domaingraph.get("yxy_is_self").toString());
yxysendsmtpinfo.setSmtp_service_isyxy(isself);
//密码加密
DES_Encrypt desEncrypt = new DES_Encrypt();
desEncrypt.setKey("06");
desEncrypt.setEncString(yxysendsmtpinfo.getSmtp_service_password());
yxysendsmtpinfo.setSmtp_service_password(desEncrypt.getStrMi());
yxysendsmtpinfoservice.addSmtpinfo(yxysendsmtpinfo);
result="1";
} catch (Exception e) {
result="0";
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return SUCCESS;
}
/**SMTP账号是否存在*/
public String findBySmtp(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
smtplist=yxysendsmtpinfoservice.findByAccount(loginid, domain, account);
if(smtplist.size()>0){
result="0";
}else{
result="1";
}
} catch (Exception e) {
result="0";
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return SUCCESS;
}
/**SMTP服务器删除*/
public String delSmtp(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
yxysendsmtpinfoservice.delSmtp(smtpid);
result="1";
} catch (Exception e) {
result="0";
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return SUCCESS;
}
/**模糊查询SMTP*/
public String findSmtpLike(){
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
smtplist=yxysendsmtpinfoservice.findByLike(loginid, domain, account);
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
}
return "list";
}
/**SMTP服务器验证*/
public String connectionService() {
try {
//获取用户session
ActionContext ac = ActionContext.getContext();
Map<String,Object> sess = ac.getSession();
YxyUserInfo user=(YxyUserInfo) sess.get("yxyuser");
loginid=user.getLogin_id();//用户账号
domain=user.getDomain();//用户所属域名
String smtphost=yxysendsmtpinfo.getSmtp_service_number();
String smtpname=yxysendsmtpinfo.getSmtp_service_account();
//解密密码
DES_Encrypt desEncrypt = new DES_Encrypt();
desEncrypt.setKey("06");
desEncrypt.setDesString(yxysendsmtpinfo.getSmtp_service_password());
String smtppass=desEncrypt.getStrM();//smtp密码需要解密
String isport=yxysendsmtpinfo.getSmtp_is_ssl()+"";
String port=yxysendsmtpinfo.getSmtp_service_port();
Properties props = new Properties();
props.put("mail.smtp.host", smtphost);
props.put("mail.smtp.auth", "true");// 设定发送邮件时需要进行身份验证
String ishost=smtphost.split("\\.")[1];
//判断是否需要ssl验证
if(isport!=null&&!isport.equals("0")&&isport.equals("1")){
if("gmail".equals(ishost)){
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.port", port);
props.put("mail.smtp.socketFactory.port", port);
}else{
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.port", port);
}
}
javax.mail.Session mailSession = javax.mail.Session.getInstance(props);
mailSession.setDebug(false);
Transport transport = mailSession.getTransport("smtp");
transport.connect(smtphost, smtpname, smtppass);
result="1";
return SUCCESS;
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw, true));
String str = sw.toString();
LogClass.errolog(str,loginid+"@"+domain);
if(str.indexOf("wrong password")!=-1||str.indexOf("AuthenticationFailedException")!=-1){//密码错
result="2";
return SUCCESS;
}else if(str.indexOf("login failed")!=-1){//服务器登录失败
result="3";
return SUCCESS;
}else if(str.indexOf("Could not connect to SMTP host")!=-1){//不能链接服务器
result="4";
return SUCCESS;
}else{
result="0";
return SUCCESS;
}
}
}
private String loginid="erro";
private String domain="erro";
private String result;//返回结果
private String account;//SMTP帐号
private int smtpid;//SMTPID
private List<YxySendSmtpInfo> smtplist=new ArrayList<YxySendSmtpInfo>();
private List<YxySmtpList> smtplistall=new ArrayList<YxySmtpList>();
private YxySendSmtpInfo yxysendsmtpinfo;//smtp pojo
private YxySendSmtpInfoService yxysendsmtpinfoservice;//SMTP Service
public YxySendSmtpInfoService getYxysendsmtpinfoservice() {
return yxysendsmtpinfoservice;
}
public void setYxysendsmtpinfoservice(
YxySendSmtpInfoService yxysendsmtpinfoservice) {
this.yxysendsmtpinfoservice = yxysendsmtpinfoservice;
}
public List<YxySendSmtpInfo> getSmtplist() {
return smtplist;
}
public void setSmtplist(List<YxySendSmtpInfo> smtplist) {
this.smtplist = smtplist;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public List<YxySmtpList> getSmtplistall() {
return smtplistall;
}
public void setSmtplistall(List<YxySmtpList> smtplistall) {
this.smtplistall = smtplistall;
}
public YxySendSmtpInfo getYxysendsmtpinfo() {
return yxysendsmtpinfo;
}
public void setYxysendsmtpinfo(YxySendSmtpInfo yxysendsmtpinfo) {
this.yxysendsmtpinfo = yxysendsmtpinfo;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public int getSmtpid() {
return smtpid;
}
public void setSmtpid(int smtpid) {
this.smtpid = smtpid;
}
}