Completed
Push — master ( 1b8e23...81a01d )
by Vijay
9s
created

EmailThread   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 3 1
A run() 0 5 2
1
import threading
2
3
from django.conf import settings
4
from django.core.mail import EmailMultiAlternatives
5
6
7
def send_email_to_list(subject, body, users_list, text_body,
8
                       bcc_admins=True, bcc_managers=False):
9
    bcc = []
10
    if bcc_admins:
11
        bcc += [email for name, email in settings.ADMINS]  # @UnusedVariable
12
13
    if bcc_managers:
14
        bcc += [email for name, email in settings.MANAGERS]  # @UnusedVariable
15
    from_user = 'PythonExpress <[email protected]>'
16
    email = EmailMultiAlternatives(
17
        subject, text_body, from_user, users_list, bcc)
18
    email.attach_alternative(body, "text/html")
19
    EmailThread(email).start()
20
21
22
def send_email_to_id(subject, body, email_id, text_body,
23
                     bcc_admins=True, bcc_managers=False):
24
    bcc = []
25
    if bcc_admins:
26
        bcc += [email for name, email in settings.ADMINS]  # @UnusedVariable
27
28
    if bcc_managers:
29
        bcc += [email for name, email in settings.MANAGERS]  # @UnusedVariable
30
31
    from_user = 'PythonExpress <[email protected]>'
32
    email = EmailMultiAlternatives(
33
        subject, text_body, from_user, [email_id], bcc=bcc)
34
    email.attach_alternative(body, "text/html")
35
    EmailThread(email).start()
36
37
38
class EmailThread(threading.Thread):
39
40
    def __init__(self, email):
41
        self.email = email
42
        threading.Thread.__init__(self)
43
44
    def run(self):
45
        try:
46
            self.email.send()
47
        except Exception as e:
48
            print(e)
49