java.lang.IllegalStateException: Illegal access: this web application instance has been stopped alr
阿新 • • 發佈:2020-10-09
import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication from com.myconf import conf #獲取配置檔案中的資訊 def send_email(file_path,file_name): # 第一步連線到smtp伺服器 smtp=smtplib.SMTP_SSL("smtp.qq.com",465) smtp.login(conf.get('email','sender'),conf.get('email','sender_pwd')) # 第二步構建郵件 smg=MIMEMultipart() text_smg = MIMEText(open(file_path, 'r', encoding='utf8').read(), "html") # 郵件型別:html格式,plain是文字 smg.attach(text_smg) file_msg = MIMEApplication(open(file_path, "rb").read()) file_msg.add_header('content-disposition', 'attachment', filename=file_name) smg.attach(file_msg) smg["Subject"] = conf.get('email','subject') smg["From"] = conf.get('email','sender') smg["To"] = conf.get('email','receiver') # 第三步傳送郵件 smtp.send_message(smg,from_addr=conf.get('email','sender'),to_addrs=conf.get('email','receiver')) if __name__ == '__main__': pass