Skip to main content
 首页 » 编程设计

python之我想每天上午 11 点发送电子邮件

2024年09月03日32duanxz

我想在每天上午 11 点使用 Python 发送一封电子邮件。 但是我不知道每天上午11点发送。现在,我可以写一个代码来发送电子邮件。

from django.core.mail import EmailMessage 
 
def send?email(self): 
        email = EmailMessage(subject, message, None, email_to) 
        email.send(fail_silently=False) 

我查了这个文档,但是找不到如何在指定时间发送邮件。 https://docs.python.org/3/library/email.message.html

请您参考如下方法:

您需要在需要的时间使用 cron(在 Linux 上)或 at(在 Windows 上)。

这个链接是一个很好的起点 https://medium.com/@harishoraon/writing-your-first-cron-job-in-django-ed62b805d822