Files
Quant_Code/3.新闻抓取与通知/send_mail_test.py
2025-04-09 17:18:30 +08:00

43 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from datetime import datetime, timedelta
# 加入邮件通知
import smtplib
from email.mime.text import MIMEText # 导入 MIMEText 类发送纯文本邮件
from email.mime.multipart import MIMEMultipart # 导入 MIMEMultipart 类发送带有附件的邮件
from email.mime.application import MIMEApplication # 导入 MIMEApplication 类发送二进制附件
## 配置邮件信息
receivers = ["*****@qq.com"] # 设置邮件接收人地址
subject = "订单流策略交易信号" # 设置邮件主题
#text = " " # 设置邮件正文
# file_path = "test.txt" # 设置邮件附件文件路径
## 配置邮件服务器信息
smtp_server = "smtp.qq.com" # 设置发送邮件的 SMTP 服务器地址
smtp_port = 465 # 设置发送邮件的 SMTP 服务器端口号,一般为 25 端口 465
sender = "***@qq.com" # 设置发送邮件的邮箱地址
username = "***@@qq.com" # 设置发送邮件的邮箱用户名
password = "osjyjmbqrzxtbjbf" #zrmpcgttataabhjh设置发送邮件的邮箱密码或授权码
def send_mail(text):
msg = MIMEMultipart()
msg["From"] = sender
msg["To"] = ";".join(receivers)
msg["Subject"] = subject
msg.attach(MIMEText(text, "plain", "utf-8"))
smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)
# smtp = smtplib.SMTP_SSL(smtp_server)
smtp.login(username, password)
smtp.sendmail(sender, receivers, msg.as_string())
smtp.quit()
# 获取当前时间
now = datetime.now()
# 判断当前时间是否为15:30:00
if now.strftime('%H:%M:%S') == '15:30:00':
print("当前时间是15:30:00。")
send_mail("当前时间是21:45:00")
else:
print("当前时间不是15:30:00。")
send_mail("当前时间不是是21:45:00")