|
8 | 8 | from app.db import Session
|
9 | 9 | from app.email_utils import send_email, render
|
10 | 10 | from app.log import LOG
|
11 |
| -from app.models import ( |
12 |
| - User, |
13 |
| - Mailbox, |
14 |
| -) |
| 11 | +from app.models import * |
15 | 12 | from job_runner import (
|
16 | 13 | onboarding_pgp,
|
17 | 14 | onboarding_browser_extension,
|
@@ -42,119 +39,5 @@ def reset_db():
|
42 | 39 | create_db()
|
43 | 40 |
|
44 | 41 |
|
45 |
| -def send_mailbox_newsletter(): |
46 |
| - for user in User.order_by(User.id).all(): |
47 |
| - if user.notification and user.activated: |
48 |
| - try: |
49 |
| - LOG.d("Send newsletter to %s", user) |
50 |
| - send_email( |
51 |
| - user.email, |
52 |
| - "Introducing Mailbox - our most requested feature", |
53 |
| - render("com/newsletter/mailbox.txt", user=user), |
54 |
| - render("com/newsletter/mailbox.html", user=user), |
55 |
| - ) |
56 |
| - sleep(1) |
57 |
| - except Exception: |
58 |
| - LOG.w("Cannot send to user %s", user) |
59 |
| - |
60 |
| - |
61 |
| -def send_pgp_newsletter(): |
62 |
| - for user in User.order_by(User.id).all(): |
63 |
| - if user.notification and user.activated: |
64 |
| - try: |
65 |
| - LOG.d("Send PGP newsletter to %s", user) |
66 |
| - send_email( |
67 |
| - user.email, |
68 |
| - "Introducing PGP - encrypt your emails so only you can read them", |
69 |
| - render("com/newsletter/pgp.txt", user=user), |
70 |
| - render("com/newsletter/pgp.html", user=user), |
71 |
| - ) |
72 |
| - sleep(1) |
73 |
| - except Exception: |
74 |
| - LOG.w("Cannot send to user %s", user) |
75 |
| - |
76 |
| - |
77 |
| -def send_mobile_newsletter(): |
78 |
| - count = 0 |
79 |
| - for user in User.order_by(User.id).all(): |
80 |
| - if user.notification and user.activated: |
81 |
| - count += 1 |
82 |
| - try: |
83 |
| - LOG.d("#%s: send to %s", count, user) |
84 |
| - send_email( |
85 |
| - user.email, |
86 |
| - "Mobile and Dark Mode", |
87 |
| - render("com/newsletter/mobile-darkmode.txt", user=user), |
88 |
| - render("com/newsletter/mobile-darkmode.html", user=user), |
89 |
| - ) |
90 |
| - except Exception: |
91 |
| - LOG.w("Cannot send to user %s", user) |
92 |
| - |
93 |
| - if count % 5 == 0: |
94 |
| - # sleep every 5 sends to avoid hitting email limits |
95 |
| - LOG.d("Sleep 1s") |
96 |
| - sleep(1) |
97 |
| - |
98 |
| - |
99 |
| -def disable_mailbox(mailbox_id): |
100 |
| - """disable a mailbox and all of its aliases""" |
101 |
| - mailbox = Mailbox.get(mailbox_id) |
102 |
| - mailbox.verified = False |
103 |
| - for alias in mailbox.aliases: |
104 |
| - alias.enabled = False |
105 |
| - |
106 |
| - Session.commit() |
107 |
| - |
108 |
| - email_msg = f"""Hi, |
109 |
| -
|
110 |
| - Your mailbox {mailbox.email} cannot receive emails. |
111 |
| - To avoid forwarding emails to an invalid mailbox, we have disabled this mailbox along with all of its aliases. |
112 |
| -
|
113 |
| - If this is a mistake, please reply to this email. |
114 |
| -
|
115 |
| - Thanks, |
116 |
| - SimpleLogin team. |
117 |
| - """ |
118 |
| - |
119 |
| - try: |
120 |
| - send_email( |
121 |
| - mailbox.user.email, |
122 |
| - f"{mailbox.email} is disabled", |
123 |
| - email_msg, |
124 |
| - email_msg.replace("\n", "<br>"), |
125 |
| - ) |
126 |
| - except Exception: |
127 |
| - LOG.e("Cannot send disable mailbox email to %s", mailbox.user) |
128 |
| - |
129 |
| - |
130 |
| -def send_onboarding_emails(user): |
131 |
| - onboarding_send_from_alias(user) |
132 |
| - onboarding_mailbox(user) |
133 |
| - onboarding_browser_extension(user) |
134 |
| - onboarding_pgp(user) |
135 |
| - |
136 |
| - |
137 | 42 | if __name__ == "__main__":
|
138 |
| - # to test email template |
139 |
| - # with open("/tmp/email.html", "w") as f: |
140 |
| - # user = User.first() |
141 |
| - # f.write( |
142 |
| - # render( |
143 |
| - # "transactional/reset-password.html", |
144 |
| - # email=user.email, |
145 |
| - # user=user, |
146 |
| - # name=user.name, |
147 |
| - # activation_link="https://ab.cd", |
148 |
| - |
149 |
| - # directory="dir", |
150 |
| - # domain="domain", |
151 |
| - |
152 |
| - # current_email="[email protected]", |
153 |
| - # link="https://link.com", |
154 |
| - # mailbox_email="[email protected]", |
155 |
| - |
156 |
| - # reset_password_link="http://reset_password_link", |
157 |
| - # ) |
158 |
| - # ) |
159 |
| - |
160 | 43 | embed()
|
0 commit comments