Python django_cron不发送电子邮件
我刚刚安装了Python django_cron不发送电子邮件,python,django,email,cron,Python,Django,Email,Cron,我刚刚安装了django\u cronnotdjango\u crontab,但不知怎的,我试图发送一封电子邮件作为通知,但它就是不起作用 这只是为了测试,所以我将其设置为1分钟。 之前的代码有点复杂,但不起作用,所以我使用最简单的方式发送电子邮件,以确保它不起作用。甚至还将其用作测试的post方法,如果一个post方法调用follow-code,那么它可以完美地工作 class MyCronJob(CronJobBase): RUN_EVERY_MINS = 1 # every mi
django\u cron
notdjango\u crontab
,但不知怎的,我试图发送一封电子邮件作为通知,但它就是不起作用
这只是为了测试,所以我将其设置为1分钟。
之前的代码有点复杂,但不起作用,所以我使用最简单的方式发送电子邮件,以确保它不起作用。甚至还将其用作测试的post
方法,如果一个post方法调用follow-code,那么它可以完美地工作
class MyCronJob(CronJobBase):
RUN_EVERY_MINS = 1 # every minute
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'Email_Test' # a unique code
def do(self):
print('######################################')
send_mail(
'Subject here from cron',
'Here is the message.',
'from@email.com',
['to@emailcom'],
fail_silently=False,
)
我试着运行python manage.py runcrons
和python manage.py runcrons--force
并等待,(没有错误,我还添加了print
,因为我想看看代码是否运行良好,我看到打印出来的代码)
有人能给我一个建议吗
提前感谢尝试发送邮件的自定义功能。我尝试了send\u mail
功能,但它对我不起作用,我也没有发现任何关于这个主题的错误或解释。下面是一个使用
尝试使用自定义功能发送邮件。我尝试了send\u mail
功能,但它对我不起作用,我也没有发现任何关于这个主题的错误或解释。下面是一个使用
请确保首先必须使用send_mail从django.core.mail导入库。我知道现在帮不上忙了,但你可以试试这个
from django_cron import CronJobBase, Schedule
from django.core.mail import send_mail
class my_scheduled_job(CronJobBase):
RUN_EVERY_MINS = 1
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'user_dashboard.autoemail.my_scheduled_job'
def do(self):
subject= 'Send Email With Automatic Schedule'
message= 'Test send email :'
email_to= ['xxxxxxxx@gmail.com']
email_user(subject_test, message_test, email_to_test)
print ("done")
def email_user(subject, message, email_to):
email_from = 'noreply@xxxx.id'
send = send_mail(subject, message, email_from, email_to)
return send
请确保首先必须使用send_mail从django.core.mail导入库。我知道现在帮不上忙了,但你可以试试这个
from django_cron import CronJobBase, Schedule
from django.core.mail import send_mail
class my_scheduled_job(CronJobBase):
RUN_EVERY_MINS = 1
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'user_dashboard.autoemail.my_scheduled_job'
def do(self):
subject= 'Send Email With Automatic Schedule'
message= 'Test send email :'
email_to= ['xxxxxxxx@gmail.com']
email_user(subject_test, message_test, email_to_test)
print ("done")
def email_user(subject, message, email_to):
email_from = 'noreply@xxxx.id'
send = send_mail(subject, message, email_from, email_to)
return send