-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
send_mass_emails.py
51 lines (36 loc) · 1.2 KB
/
send_mass_emails.py
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
51
"""
To populate telegram links into out `community` service.
How to use:
run in the terminal:
`python populate_communities.py {dev|prod}`
"""
import os
import sys
import time
settings_type = sys.argv[1]
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE", "petroly.settings." + settings_type
)
# the above line is sufficient
# settings.configure()
print("DJANGO_SETTINGS_MODULE: ", os.environ.get("DJANGO_SETTINGS_MODULE"))
def send_email():
msg = """We received huge demand on our services, and sending huge number of
emails are not possible.
if still want us to notify you please activate your Telegram from our website.
Open your tacking list from the lower right icon, then open settings
"""
for obj in TrackingList.objects.filter(channels=[ChannelEnum.EMAIL]):
user: User = obj.user
print(f"sending to {user}")
try:
user.email_user("Turning off Email Channel", msg)
except Exception as exc:
print(exc)
time.sleep(3)
if __name__ == "__main__":
import django
django.setup()
from notifier.models import TrackingList, ChannelEnum
from django.contrib.auth.models import User
send_email()