以下是一个使用Python的示例代码,用于在比赛开始前一小时发送通知:
import datetime
import time
import smtplib
def send_email(subject, body, to):
from_email = "your_email@example.com"
password = "your_email_password"
message = f"Subject: {subject}\n\n{body}"
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(from_email, password)
server.sendmail(from_email, to, message)
server.quit()
def send_notification():
current_time = datetime.datetime.now()
contest_time = current_time + datetime.timedelta(hours=1)
subject = "比赛通知"
body = "您报名的比赛将在一小时后开始,请做好准备。"
to = "recipient_email@example.com"
send_email(subject, body, to)
# 等待比赛开始前一小时
time.sleep(3600)
send_notification()
请确保将以下内容替换为您自己的信息:
your_email@example.com
:您的发件人电子邮件地址your_email_password
:您的发件人电子邮件密码recipient_email@example.com
:收件人的电子邮件地址在运行此代码之前,您需要安装smtplib
库,可以使用以下命令进行安装:
pip install secure-smtplib
请注意,此示例代码使用Gmail作为发件人邮箱,如果您使用其他邮箱,请根据需要更改SMTP服务器和端口。