STEP #1

(1/2)

此处切换ai服务商,可对比多家ai的回复,取最优解。

上一步下一步关闭
酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

写一段python代码可以定时发送邮件提醒

```python import smtplib from email.mime.text import MIMEText from email.header import Header import time import schedule def send_email(): # 邮件发送者和接收者 sender = 'your_email@example.com' receiver = 'receiver_email@example.com' # 邮件主题和内容 subject = '定时邮件提醒' content = '这是一封定时发送的邮件提醒。' # 邮件对象 message = MIMEText(content, 'plain', 'utf-8') message['From'] = Header(sender) message['To'] = Header(receiver) message['Subject'] = Header(subject) # 发送邮件 try: smtp_obj = smtplib.SMTP('smtp.example.com') smtp_obj.login(sender, 'your_email_password') smtp_obj.sendmail(sender, [receiver], message.as_string()) print("邮件发送成功") except smtplib.SMTPException as e: print("Error: 无法发送邮件", e) def job(): send_email() # 设置定时任务,每天的10:00发送邮件 schedule.every().day.at("10:00").do(job) while True: schedule.run_pending() time.sleep(60) ``` 请将上述代码中的`your_email@example.com`、`receiver_email@example.com`、`smtp.example.com`和`your_email_password`替换为实际的发件人邮箱、收件人邮箱、SMTP服务器地址和发件人邮箱密码。 [2024-06-21 17:49:11 | AI写代码神器 | 422点数解答]
相关提问