EmailThread   A
last analyzed

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
20
    EmailThread(email).start()
21
    email = EmailMultiAlternatives(
22
        subject, text_body, from_user, ['[email protected]'], bcc)
23
    email.attach_alternative(body, "text/html")
24
    EmailThread(email).start()
25
26
27
def send_email_to_id(subject, body, email_id, text_body,
28
                     bcc_admins=True, bcc_managers=False):
29
    bcc = []
30
    # if bcc_admins:
31
    #     bcc += [email for name, email in settings.ADMINS]  # @UnusedVariable
32
33
    # if bcc_managers:
34
    # bcc += [email for name, email in settings.MANAGERS]  # @UnusedVariable
35
36
    from_user = 'PythonExpress <[email protected]>'
37
    email = EmailMultiAlternatives(
38
        subject, text_body, from_user, [email_id], bcc=bcc)
39
    email.attach_alternative(body, "text/html")
40
    EmailThread(email).start()
41
    # EMail to Admins
42
    email = EmailMultiAlternatives(
43
        subject, text_body, from_user, ['[email protected]'], bcc)
44
    email.attach_alternative(body, "text/html")
45
    EmailThread(email).start()
46
47
48
class EmailThread(threading.Thread):
49
50
    def __init__(self, email):
51
        self.email = email
52
        threading.Thread.__init__(self)
53
54
    def run(self):
55
        try:
56
            self.email.send()
57
        except Exception as e:
58
            print(e)
59