|
@ -1,23 +1,20 @@
|
1
|
1
|
package com.ekexiu.console.system.service;
|
2
|
2
|
|
3
|
3
|
import com.ekexiu.console.system.mail.MailService;
|
4
|
|
import org.apache.log4j.Logger;
|
5
|
4
|
import org.jfw.apt.annotation.Autowrie;
|
6
|
5
|
import org.jfw.apt.annotation.Nullable;
|
7
|
6
|
import org.jfw.apt.web.annotation.Path;
|
8
|
7
|
import org.jfw.apt.web.annotation.operate.Post;
|
9
|
|
import org.jfw.apt.web.annotation.param.JdbcConn;
|
10
|
8
|
|
11
|
9
|
import javax.mail.MessagingException;
|
12
|
|
import java.sql.Connection;
|
13
|
|
import java.sql.SQLException;
|
|
10
|
import java.util.ArrayList;
|
|
11
|
import java.util.List;
|
14
|
12
|
|
15
|
13
|
/**
|
16
|
14
|
* Created by TT on 2017/5/11.
|
17
|
15
|
*/
|
18
|
16
|
@Path
|
19
|
17
|
public class EmailService {
|
20
|
|
private Logger logger = Logger.getLogger(EmailService.class);
|
21
|
18
|
|
22
|
19
|
@Autowrie
|
23
|
20
|
private MailService mailservice;
|
|
@ -25,10 +22,10 @@ public class EmailService {
|
25
|
22
|
private String phoneContentTemplate;
|
26
|
23
|
|
27
|
24
|
private String content = "contentKey";
|
28
|
|
private String contentDefault = "科袖网是一个为科研工作者服务的平台。我们将为您免费提供一个专属主页,您可以对外展示您的科研经历、成果以及资源,我们的平台将面向全国的企业与科研机构进行推广,您将得到更多与企业的合作、与同行交流的机会。";
|
|
25
|
private String contentDefault = "";
|
29
|
26
|
|
30
|
27
|
private String appellation = "appellationKey";
|
31
|
|
private String appellationDefault = "您好";
|
|
28
|
private String appellationDefault = "";
|
32
|
29
|
|
33
|
30
|
private String phoneReplaceKey = "mobileCode";
|
34
|
31
|
private String inviteReplacePhone = "phoneKey";
|
|
@ -136,17 +133,20 @@ public class EmailService {
|
136
|
133
|
/**
|
137
|
134
|
* 给指定邮箱发送邀请邮件
|
138
|
135
|
*
|
139
|
|
* @param con
|
140
|
136
|
* @param mobilePhones 手机号数组
|
141
|
137
|
* @param emails 邮箱
|
142
|
138
|
* @param inviteCodes 邀请码
|
143
|
|
* @throws SQLException
|
|
139
|
|
144
|
140
|
* @throws MessagingException
|
145
|
141
|
*/
|
146
|
142
|
@Post
|
147
|
143
|
@Path("/sendmail")
|
148
|
|
public int sendmail(@Nullable String content,@Nullable String appellation, @Nullable String[] mobilePhones, String[] emails, String[] inviteCodes)
|
149
|
|
throws SQLException, MessagingException {
|
|
144
|
public EmailInfo sendmail(@Nullable String content, @Nullable String appellation, @Nullable String[] mobilePhones, String[] emails, String[] inviteCodes, String[] names)
|
|
145
|
throws MessagingException {
|
|
146
|
EmailInfo emailInfo = new EmailInfo();
|
|
147
|
List<String> email = new ArrayList<>();
|
|
148
|
List<String> name = new ArrayList<>();
|
|
149
|
int count = 0;
|
150
|
150
|
for (int i = 0; i < emails.length; i++) {
|
151
|
151
|
if (mobilePhones[i] == "") {
|
152
|
152
|
mobilePhones[i] = null;
|
|
@ -157,13 +157,22 @@ public class EmailService {
|
157
|
157
|
if (appellation == null) {
|
158
|
158
|
appellation = this.appellationDefault;
|
159
|
159
|
}
|
160
|
|
this.sendInviteMail(content, appellation,emails[i], mobilePhones[i], inviteCodes[i]);
|
161
|
|
this.logger.info("成功发送邀请邮件:" + emails[i]);
|
|
160
|
try {
|
|
161
|
this.sendInviteMail(content, appellation, emails[i], mobilePhones[i], inviteCodes[i]);
|
|
162
|
} catch (MessagingException e) {
|
|
163
|
count++;
|
|
164
|
email.add(emails[i]);
|
|
165
|
name.add(names[i]);
|
|
166
|
continue;
|
|
167
|
}
|
162
|
168
|
}
|
163
|
|
return emails.length;
|
|
169
|
emailInfo.setCount(emails.length-count);
|
|
170
|
emailInfo.setEmails(email);
|
|
171
|
emailInfo.setNames(name);
|
|
172
|
return emailInfo;
|
164
|
173
|
}
|
165
|
174
|
|
166
|
|
public void sendInviteMail(String content,String appellation,String email, @Nullable String mobilePhone, String inviteCode)
|
|
175
|
public void sendInviteMail(String content, String appellation, String email, @Nullable String mobilePhone, String inviteCode)
|
167
|
176
|
throws MessagingException {
|
168
|
177
|
String mailContent = this.inviteMailContentTempalte;
|
169
|
178
|
mailContent = mailContent.replaceAll(this.inviteReplaceEmail, email);
|
|
@ -180,4 +189,36 @@ public class EmailService {
|
180
|
189
|
this.mailservice.sendSimpleMail(email, mailContent, null, this.inviteMailSubject);
|
181
|
190
|
}
|
182
|
191
|
|
|
192
|
public static class EmailInfo {
|
|
193
|
|
|
194
|
private int count;
|
|
195
|
private List<String> emails;
|
|
196
|
private List<String> names;
|
|
197
|
|
|
198
|
public List<String> getNames() {
|
|
199
|
return names;
|
|
200
|
}
|
|
201
|
|
|
202
|
public void setNames(List<String> names) {
|
|
203
|
this.names = names;
|
|
204
|
}
|
|
205
|
|
|
206
|
public int getCount() {
|
|
207
|
return count;
|
|
208
|
}
|
|
209
|
|
|
210
|
public void setCount(int count) {
|
|
211
|
this.count = count;
|
|
212
|
}
|
|
213
|
|
|
214
|
public List<String> getEmails() {
|
|
215
|
return emails;
|
|
216
|
}
|
|
217
|
|
|
218
|
public void setEmails(List<String> emails) {
|
|
219
|
this.emails = emails;
|
|
220
|
}
|
|
221
|
|
|
222
|
}
|
|
223
|
|
183
|
224
|
}
|