@@ -30,13 +30,13 @@ class UserMailer:
30
30
"""
31
31
Send emails.
32
32
"""
33
- def __init__ (self , MAIL_HOST :str , MAIL_PORT :str , MAIL_FROM : str , MAIL_PASS : str , MAIL_SSL :bool , TEST : bool = False ):
34
- self .MAIL_HOST = MAIL_HOST
35
- self .MAIL_PORT = MAIL_PORT
36
- self .MAIL_SSL = MAIL_SSL
37
- self .MAIL_FROM = MAIL_FROM
38
- self .MAIL_PASS = MAIL_PASS
39
- self .TEST = TEST
33
+ def __init__ (self , mail_host :str , mail_port :str , mail_from : str , mail_pass : str , mail_ssl :bool , test : bool = False ):
34
+ self .mail_host = mail_host
35
+ self .mail_port = mail_port
36
+ self .mail_ssl = mail_ssl
37
+ self .mail_from = mail_from
38
+ self .mail_pass = mail_pass
39
+ self .test = test
40
40
self .queue = []
41
41
42
42
def send_email_confirmation (self , user_object : User ):
@@ -51,22 +51,22 @@ def send_email_confirmation(self, user_object: User):
51
51
user = user_object .username
52
52
53
53
connection = get_connection (
54
- host = self .MAIL_HOST ,
55
- port = self .MAIL_PORT ,
56
- password = self .MAIL_PASS ,
54
+ host = self .mail_host ,
55
+ port = self .mail_port ,
56
+ password = self .mail_pass ,
57
57
fail_silently = False ,
58
- use_ssl = self .MAIL_SSL ,
59
- username = self .MAIL_FROM ,
58
+ use_ssl = self .mail_ssl ,
59
+ username = self .mail_from ,
60
60
)
61
61
email = EmailMessage (
62
62
insalan .settings .EMAIL_SUBJECT_PREFIX + _ ("Confirmez votre courriel" ),
63
63
_ ("Confirmez votre adresse de courriel en cliquant sur " ) +
64
64
f"{ insalan .settings .PROTOCOL } ://{ insalan .settings .WEBSITE_HOST } /verification/{ user } /{ token } " ,
65
- self .MAIL_FROM ,
65
+ self .mail_from ,
66
66
[user_object .email ],
67
67
connection = connection ,
68
68
)
69
- if self .TEST :
69
+ if self .test :
70
70
email .send ()
71
71
else :
72
72
self .queue .append (email )
@@ -80,11 +80,11 @@ def send_password_reset(self, user_object: User):
80
80
81
81
connection = get_connection (
82
82
fail_silently = False ,
83
- username = self .MAIL_FROM ,
84
- password = self .MAIL_PASS ,
85
- host = self .MAIL_HOST ,
86
- port = self .MAIL_PORT ,
87
- use_ssl = self .MAIL_SSL ,
83
+ username = self .mail_from ,
84
+ password = self .mail_pass ,
85
+ host = self .mail_host ,
86
+ port = self .mail_port ,
87
+ use_ssl = self .mail_ssl ,
88
88
)
89
89
email = EmailMessage (
90
90
insalan .settings .EMAIL_SUBJECT_PREFIX + _ ("Demande de ré-initialisation de mot de passe" ),
@@ -94,11 +94,11 @@ def send_password_reset(self, user_object: User):
94
94
"vous pouvez cliquer sur le lien suivant: "
95
95
) +
96
96
f"{ insalan .settings .PROTOCOL } ://{ insalan .settings .WEBSITE_HOST } /reset-password/{ user } /{ token } " ,
97
- self .MAIL_FROM ,
97
+ self .mail_from ,
98
98
[user_object .email ],
99
99
connection = connection ,
100
100
)
101
- if self .TEST :
101
+ if self .test :
102
102
email .send ()
103
103
else :
104
104
self .queue .append (email )
@@ -109,43 +109,43 @@ def send_kick_mail(self, user_object: User, team_name: str):
109
109
"""
110
110
connection = get_connection (
111
111
fail_silently = False ,
112
- username = self .MAIL_FROM ,
113
- password = self .MAIL_PASS ,
114
- host = self .MAIL_HOST ,
115
- port = self .MAIL_PORT ,
116
- use_ssl = self .MAIL_SSL ,
112
+ username = self .mail_from ,
113
+ password = self .mail_pass ,
114
+ host = self .mail_host ,
115
+ port = self .mail_port ,
116
+ use_ssl = self .mail_ssl ,
117
117
)
118
118
email = EmailMessage (
119
119
insalan .settings .EMAIL_SUBJECT_PREFIX + _ ("Vous avez été exclu.e de votre équipe" ),
120
120
_ ("Vous avez été exclu.e de l'équipe %s." ) % team_name ,
121
- self .MAIL_FROM ,
121
+ self .mail_from ,
122
122
[user_object .email ],
123
123
connection = connection ,
124
124
)
125
- if self .TEST :
125
+ if self .test :
126
126
email .send ()
127
127
else :
128
128
self .queue .append (email )
129
129
130
130
def send_ticket_mail (self , user_object : User , ticket : str ):
131
131
"""
132
- Send a mail to a user that has been kicked .
132
+ Send a mail with the ticket in attachment .
133
133
"""
134
134
135
135
ticket_pdf = TicketManager .generate_ticket_pdf (ticket )
136
136
137
137
connection = get_connection (
138
138
fail_silently = False ,
139
- username = self .MAIL_FROM ,
140
- password = self .MAIL_PASS ,
141
- host = self .MAIL_HOST ,
142
- port = self .MAIL_PORT ,
143
- use_ssl = self .MAIL_SSL ,
139
+ username = self .mail_from ,
140
+ password = self .mail_pass ,
141
+ host = self .mail_host ,
142
+ port = self .mail_port ,
143
+ use_ssl = self .mail_ssl ,
144
144
)
145
145
email = EmailMessage (
146
146
insalan .settings .EMAIL_SUBJECT_PREFIX + _ ("Votre billet pour l'InsaLan" ),
147
147
_ ("Votre inscription pour l'Insalan a été payée. Votre billet est disponible en pièce jointe. Vous pouvez retrouver davantages d'informations sur l'évènement sur le site internet de l'InsaLan." ),
148
- self .MAIL_FROM ,
148
+ self .mail_from ,
149
149
[user_object .email ],
150
150
connection = connection ,
151
151
)
@@ -155,7 +155,7 @@ def send_ticket_mail(self, user_object: User, ticket: str):
155
155
"application/pdf"
156
156
)
157
157
158
- if self .TEST :
158
+ if self .test :
159
159
email .send ()
160
160
else :
161
161
self .queue .append (email )
@@ -166,23 +166,23 @@ def send_tournament_mail(self, user_object: User, title: str, content: str, atta
166
166
"""
167
167
connection = get_connection (
168
168
fail_silently = False ,
169
- username = self .MAIL_FROM ,
170
- password = self .MAIL_PASS ,
171
- host = self .MAIL_HOST ,
172
- port = self .MAIL_PORT ,
173
- use_ssl = self .MAIL_SSL ,
169
+ username = self .mail_from ,
170
+ password = self .mail_pass ,
171
+ host = self .mail_host ,
172
+ port = self .mail_port ,
173
+ use_ssl = self .mail_ssl ,
174
174
)
175
175
email = EmailMessage (
176
176
insalan .settings .EMAIL_SUBJECT_PREFIX + title ,
177
177
content ,
178
- self .MAIL_FROM ,
178
+ self .mail_from ,
179
179
[user_object .email ],
180
180
connection = connection ,
181
181
)
182
182
if attachment :
183
183
email .attach (attachment .name , attachment .read ())
184
184
185
- if self .TEST :
185
+ if self .test :
186
186
email .send ()
187
187
else :
188
188
self .queue .append (email )
@@ -203,13 +203,13 @@ class MailManager:
203
203
mailers = {}
204
204
205
205
@staticmethod
206
- def get_mailer (MAIL_FROM : str ) -> UserMailer :
206
+ def get_mailer (mail_from : str ) -> UserMailer :
207
207
"""
208
208
Get a mailer for a specific email address.
209
209
"""
210
- if MAIL_FROM not in MailManager .mailers :
210
+ if mail_from not in MailManager .mailers :
211
211
return None
212
- return MailManager .mailers [MAIL_FROM ]
212
+ return MailManager .mailers [mail_from ]
213
213
214
214
@staticmethod
215
215
def get_default_mailer () -> UserMailer :
@@ -221,11 +221,11 @@ def get_default_mailer() -> UserMailer:
221
221
return list (MailManager .mailers .values ())[0 ]
222
222
223
223
@staticmethod
224
- def add_mailer (MAIL_HOST :str , MAIL_PORT : str , MAIL_FROM : str , MAIL_PASS : str , MAIL_SSL :bool , TEST : bool = False ):
224
+ def add_mailer (mail_host :str , mail_port : str , mail_from : str , mail_pass : str , mail_ssl :bool , test : bool = False ):
225
225
"""
226
226
Add a mailer for a specific email address.
227
227
"""
228
- MailManager .mailers [MAIL_FROM ] = UserMailer (MAIL_HOST , MAIL_PORT , MAIL_FROM , MAIL_PASS , MAIL_SSL , TEST = TEST )
228
+ MailManager .mailers [mail_from ] = UserMailer (mail_host , mail_port , mail_from , mail_pass , mail_ssl , test = test )
229
229
230
230
@staticmethod
231
231
def send_queued_mail ():
@@ -240,16 +240,16 @@ def start_scheduler():
240
240
logging .getLogger ('apscheduler.executors.default' ).setLevel (logging .WARNING )
241
241
242
242
# Check if we are in test mode
243
- TEST = 'test' in sys .argv
244
- print (TEST , file = sys .stderr )
243
+ test = 'test' in sys .argv
244
+ print (test , file = sys .stderr )
245
245
246
246
# Add mailers
247
247
for auth in insalan .settings .EMAIL_AUTH :
248
248
mailer = insalan .settings .EMAIL_AUTH [auth ]
249
- MailManager .add_mailer (mailer ["host" ], mailer ["port" ], mailer ["from" ], mailer ["pass" ], mailer ["ssl" ], TEST = TEST )
249
+ MailManager .add_mailer (mailer ["host" ], mailer ["port" ], mailer ["from" ], mailer ["pass" ], mailer ["ssl" ], test = test )
250
250
251
251
# Start scheduler
252
- if not TEST :
252
+ if not test :
253
253
scheduler = BackgroundScheduler ()
254
254
scheduler .add_job (MailManager .send_queued_mail , 'interval' , seconds = 30 )
255
255
scheduler .start ()
0 commit comments