15 发邮件

master
markma 3 years ago
parent b0208026bc
commit c7b46fda11

@ -0,0 +1,102 @@
import base64
import sys
from socket import *
toemail = sys.argv[1]
print(toemail)
msg = "\r\n 您的国防科大请销假系统注册成功。"
endmsg = "\r\n.\r\n"
# Choose a mail server (e.g. Google mail server) and call it mailserver
mailserver = "smtp.qq.com" # 网上查询到qq邮箱的SMTP服务器
# Create socket called clientSocket and establish a TCP connection with mailserver
# Fill in start
ID = base64.b64encode(b"750975972@qq.com").decode() + '\r\n' # 账户名登录用需要利用库base64转换
password = base64.b64encode(b"semjskwgqfwkbcfd").decode() + '\r\n' # 授权码登录时代替密码需要利用库base64转换
clientSocket = socket(AF_INET, SOCK_STREAM) # 与之前webserver实验相同仍然是创建一个IPv4SOCK_STREAM类型的客户套接字
serverPort = 25
clientSocket.connect((mailserver, serverPort)) # 客户套接字尝试创建与SMTP服务器指定端口的连接
# Fill in end
recv = clientSocket.recv(1024).decode()
print(recv)
if recv[:3] != '220':
print('!220 reply not received from server.')
# Send HELO command and print server response.
heloCommand = 'HELO Alice\r\n' # HELO握手确认双方在线
clientSocket.send(heloCommand.encode())
recv1 = clientSocket.recv(1024).decode()
print(recv1)
if recv1[:3] != '250':
print('!250 reply not received from server.')
mailCommand = "AUTH LOGIN\r\n" # AUTH登录请求qq邮箱需要登录才能进行收发邮件功能
clientSocket.send(mailCommand.encode())
recv1 = clientSocket.recv(1024).decode()
print(recv1)
if recv1[:3] != '334':
print('!334 need login')
clientSocket.send(ID.encode()) # 发送账户名
recv1 = clientSocket.recv(1024).decode()
print(recv1)
if recv1[:3] != '334':
print('!334 need login')
clientSocket.send(password.encode()) # 发送授权码
recv1 = clientSocket.recv(1024).decode()
print(recv1)
if recv1[:3] != '235':
print('!235 password error')
# Send MAIL FROM command and print server response.
# Fill in start
mailCommand = "MAIL FROM: <750975972@qq.com>\r\n" # 正式进入发件环节MAIL FROM填写发件人
clientSocket.send(mailCommand.encode())
recv1 = clientSocket.recv(1024).decode()
print(recv1)
if recv1[:3] != '250':
print('!250 reply not received from server.')
# Fill in end
# Send RCPT TO command and print server response.
# Fill in start
mailCommand = "RCPT TO: <" + toemail + ">\r\n" # RCPT TO填写收件人
clientSocket.send(mailCommand.encode())
recv1 = clientSocket.recv(1024).decode()
print(recv1)
if recv1[:3] != '250':
print('!250 reply not received from server.')
# Fill in end
# Send DATA command and print server response.
# Fill in start
mailCommand = "DATA\r\n" # 准备发送正文,告知服务器要发送一连串的正文
clientSocket.send(mailCommand.encode())
recv1 = clientSocket.recv(1024).decode()
print(recv1)
if recv1[:3] != '354':
print('!354 DATA error')
# Fill in end
# Send message data.
# Fill in start
clientSocket.send(
('From: 750975972@qq.com\r\nTo: ' + toemail + ' \r\nSubject: welcome!\r\n' + msg).encode()) # 告知服务器正文,附带收发信息和标题
# Fill in end
# Message ends with a single period.
# Fill in start
clientSocket.send(endmsg.encode()) # 告知服务器DATA部分结束
recv1 = clientSocket.recv(1024).decode()
print(recv1)
if recv1[:3] != '250':
print('!250 reply not received from server.')
# Fill in end
# Send QUIT command and get server response.
# Fill in start
# Fill in start
mailCommand = "QUIT\r\n" # 退出SMTP
clientSocket.send(mailCommand.encode())
recv1 = clientSocket.recv(1024).decode()
print(recv1)
if recv1[:3] != '221':
print('!221 quit error')
clientSocket.close() # 关闭TCP
sys.exit()
# Fill in end

@ -203,4 +203,88 @@ public class DataAnalysis {
return result; return result;
//res = String.valueOf(cal.get(Calendar.HOUR_OF_DAY)); //res = String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
} }
@GetMapping("/place/{userid}")
public List<Map<String, String>> Place(@PathVariable("userid") String userid) {
List<LeaveDetail> LDs = leaveDetailRepository.findAll();
List<Map<String, String>> result = new ArrayList<>();
List<String> place = new ArrayList<>();
List<Integer> value = new ArrayList<>();
Map<String, String> temp = new HashMap<String, String>();
int len = LDs.size();
LeaveDetail LD;
for (int i = 0; i < len; i++) {
LD = LDs.get(i);
if (!userid.equals("*")) {
if (!LD.getUserid().toString().equals(userid)) {
continue;
}
}
String tempPlace = LDs.get(i).getPlace();
int check = -1;
for (int j = 0; j < place.size(); j++) {
if (place.get(j).equals(tempPlace)) {
check = j;
break;
}
}
if (check == -1) {
place.add(tempPlace);
value.add(1);
} else {
value.set(check, value.get(check) + 1);
}
}
int len_place = place.size();
for (int i = 0; i < len_place; i++) {
temp.put("place", place.get(i));
temp.put("value", value.get(i).toString());
Map<String, String> temp_cpy = new HashMap<String, String>();
mapCopy(temp, temp_cpy);
result.add(temp_cpy);
}
return result;
}
@GetMapping("/reason/{userid}")
public List<Map<String, String>> Reason(@PathVariable("userid") String userid) {
List<LeaveDetail> LDs = leaveDetailRepository.findAll();
List<Map<String, String>> result = new ArrayList<>();
List<String> reason = new ArrayList<>();
List<Integer> value = new ArrayList<>();
Map<String, String> temp = new HashMap<String, String>();
int len = LDs.size();
LeaveDetail LD;
for (int i = 0; i < len; i++) {
LD = LDs.get(i);
if (!userid.equals("*")) {
if (!LD.getUserid().toString().equals(userid)) {
continue;
}
}
String tempPlace = LDs.get(i).getReason();
int check = -1;
for (int j = 0; j < reason.size(); j++) {
if (reason.get(j).equals(tempPlace)) {
check = j;
break;
}
}
if (check == -1) {
reason.add(tempPlace);
value.add(1);
} else {
value.set(check, value.get(check) + 1);
}
}
int len_place = reason.size();
for (int i = 0; i < len_place; i++) {
temp.put("reason", reason.get(i));
temp.put("value", value.get(i).toString());
Map<String, String> temp_cpy = new HashMap<String, String>();
mapCopy(temp, temp_cpy);
result.add(temp_cpy);
}
return result;
}
} }

@ -11,8 +11,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.File; import java.io.*;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -230,6 +229,7 @@ public class UserDetailHandler {
user.setType(UAD.getType()); user.setType(UAD.getType());
userDetailRepository.save(UD); userDetailRepository.save(UD);
userRepository.save(user); userRepository.save(user);
email(UAD.getEmail());
userAllDetailRepository.deleteById(id); userAllDetailRepository.deleteById(id);
} }
@ -238,5 +238,25 @@ public class UserDetailHandler {
userAllDetailRepository.deleteById(id); userAllDetailRepository.deleteById(id);
} }
public void email(String address) {
Process process = null;
try {
process = Runtime.getRuntime().exec("python D:\\leave_manager_spb\\leave_manager_spb\\src\\main\\java\\com\\markma\\leave_manager_spb\\SMTP.py " + address);
} catch (IOException e) {
e.printStackTrace();
}
try (InputStream fis = process.getInputStream();
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr)) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
} }

@ -18,4 +18,5 @@ public class UserAllDetail {
private String type; private String type;
private String school_id; private String school_id;
private String name; private String name;
private String email;
} }

Loading…
Cancel
Save