-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
50 lines (42 loc) · 1.3 KB
/
script.py
File metadata and controls
50 lines (42 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'to_do_list.settings')
django.setup()
from reminder.models import Details
from django.contrib.auth.models import User
import datetime
import smtplib
import time
def send():
now = datetime.datetime.now()
now_s = now.strftime("%Y-%m-%d"+'T'+"%H:%M")
time_of_user = Details.objects.values_list('datetime',flat=True)
if now_s in time_of_user:
mail_time = Details.objects.get(datetime=now_s)
name = str(mail_time.user)
message_detail = str(mail_time.detail)
print(message_detail)
mail_send = User.objects.get(username=name)
mail = str(mail_send.email)
print(mail)
try:
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login("sender mail", "password")
message = f"""
To: {mail}
Subject: Reminder for your work
Reminder
Your Work: {message_detail}
This mail is computer generated and therefore does not reply to it.
"""
server.sendmail("sender mail",mail , message)
server.quit()
time.sleep(59)
print("Email successfully sent")
except:
print("Mail not sent")
if __name__ == "__main__":
while True:
send()