学工管理系统




import os
from PIL import Image
def validate_attachment(file_path):
if not os.path.exists(file_path):
return "文件不存在,请重新上传"
try:
img = Image.open(file_path)
img.verify()
return "文件格式正确"
except Exception as e:
return f"文件格式错误: {e}"
# 示例调用
result = validate_attachment("student_doc/attachment.jpg")
print(result)
]]>
import smtplib
from email.mime.text import MIMEText
def send_email(subject, body, to_email):
sender_email = "your_email@example.com"
password = "your_password"
message = MIMEText(body)
message['Subject'] = subject
message['From'] = sender_email
message['To'] = to_email
try:
with smtplib.SMTP_SSL('smtp.example.com', 465) as server:
server.login(sender_email, password)
server.sendmail(sender_email, to_email, message.as_string())
return "邮件发送成功"
except Exception as e:
return f"邮件发送失败: {e}"
# 示例调用
result = send_email("请假申请通知", "学生已提交请假申请,请审核!", "counselor@example.com")
print(result)
]]>