I am using Pythonanywhere (PA) and like to use the PA's task scheduler (it runs every day and checks if it is Wednesday or not) to send scheduled emails. I made a new file in my app folder called: weeklyemailmm.py
. The email settings in the setting.py works with other emailing stuff on my site. What am I doing wrong?
I try to use the code below:
from django.core.mail import send_mail
import datetime
from django.conf import settings
settings.configure(settings, DEBUG=True)
today = datetime.date.today()
weekday = today.weekday()
subject = 'New weekly email'
message = 'Hi there!'
if (weekday == 2):
try:
send_mail(
'Subject here',
'Here is the message.',
'from@gmail.com',
['to@gmail.com'],
fail_silently=False,
)
print('It is Wednesday, email sent')
except:
print('It is not Wednesday')
else:
print('Email does not sent')
On this way I always get It is not Wednesday
.
If I delete the try-except part and outdent it says:
RecursionError: maximum recursion depth exceeded while calling a Python object
If I delete the settings.configure(settings, DEBUG=True) that could be possibly wrong it say:
django.core.exceptions.ImproperlyConfigured: Requested setting EMAIL_BACKEND, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.