SChedule email

49 views
Skip to first unread message

divya murugulla

unread,
Jul 1, 2021, 8:54:31 AM7/1/21
to Django users
HI,

I wanted to schedule a email every jan and aug 6 monthly basis without celery using settings.py. Can anyone help?

once in every 6months mail should be triggered

Julio Cojom

unread,
Jul 1, 2021, 8:57:08 AM7/1/21
to django...@googlegroups.com
I remember a python library called django-cron, it's stable in Linux environments

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ba849b82-e054-45a8-ae1e-e67cde6b23b5n%40googlegroups.com.

Aadil Rashid

unread,
Jul 1, 2021, 8:57:51 AM7/1/21
to django...@googlegroups.com
Use Django-celery

--

divya murugulla

unread,
Jul 1, 2021, 9:15:09 AM7/1/21
to Django users
i cannot use celery suggest me something different

sachinbg sachin

unread,
Jul 1, 2021, 9:26:39 AM7/1/21
to django...@googlegroups.com
look for the croon jobs or schedulers that may work,

thank you
Sachin b.g

divya murugulla

unread,
Jul 1, 2021, 9:38:59 AM7/1/21
to Django users
can you please send me some code sample that i can achieve through settings

SKYLINE TV

unread,
Jul 1, 2021, 5:28:17 PM7/1/21
to Django users
You can check out celery and how to integrate it with django. Once done, task scheduling is easy,first add your gmail configuration in settings.py as follows:

EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend' 
EMAIL_USE_TLS = True 
EMAIL_HOST = 'smtp.gmail.com
EMAIL_HOST_USER = 'your_email' 
EMAIL_HOST_PASSWORD = 'your password' 
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER EMAIL_PORT = 465

Then in your tasks.py you can add the function for scheduling emails as follows:

from django.template.loader import render_to_string 
from django.core.mail import EmailMessage

@periodic_task
( run_every=(crontab(hour=3, minute=34)), #runs exactly at 3:34am every day 
name="Dispatch_scheduled_mail",
 reject_on_worker_lost=True, ignore_result=True) 
def schedule_mail(): 
 message = render_to_string('app/schedule_mail.html') 
 mail_subject = 'Scheduled Email' to_email = getmail email = EmailMessage(mail_subject, message, to=[to_email]) 
 email.send()

Then finally your email template 'schedule_mail.html
{% autoescape off %} 
Hello , 
 This is a test email if you are seeing this,
 your email got delivered! 
 Regards, Coding Team.
 {% endautoescape %}

Luis Zárate

unread,
Jul 1, 2021, 8:53:37 PM7/1/21
to django...@googlegroups.com
You can create a custom command using this doc

Now, you can call it like

python manage.py mycustomcommandname

so in Linux environment  you can use crontab (with crontab -e) to execute the command.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.


--
"La utopía sirve para caminar" Fernando Birri


Reply all
Reply to author
Forward
0 new messages