Subversion Repositories SmartDukaan

Rev

Rev 3086 | Rev 3425 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3086 Rev 3400
Line 6... Line 6...
6
 
6
 
7
class EmailSender():
7
class EmailSender():
8
    def __init__(self):
8
    def __init__(self):
9
        self.email_schedular = sched.scheduler(time.time, time.sleep)
9
        self.email_schedular = sched.scheduler(time.time, time.sleep)
10
        self.time_to_sleep = 20
10
        self.time_to_sleep = 20
-
 
11
        
-
 
12
        try:
-
 
13
            self.mailServer = smtplib.SMTP("smtp.gmail.com", 587)
-
 
14
            
-
 
15
            self.sender = "help@shop2020.in"
-
 
16
            self.password = "5h0p2o2o"
-
 
17
            self.mailServer.ehlo()
-
 
18
            self.mailServer.starttls()
-
 
19
            self.mailServer.ehlo()
-
 
20
            self.mailServer.login(self.sender, self.password)
-
 
21
 
11
        print "EmailSender initiated at ", time.time()
22
            print "EmailSender initiated at ", time.time()
-
 
23
            
-
 
24
        except smtplib.SMTPConnectError as e:
-
 
25
            print 'Specified host did not respond correctly', e
-
 
26
        
-
 
27
        except smtplib.SMTPHeloError as e:
-
 
28
            print 'The server did not reply properly to the HELO greeting.', e
-
 
29
        
-
 
30
        except smtplib.SMTPAuthenticationError as e:
-
 
31
            print 'The server did not accept the username/password combination.', e
-
 
32
        
-
 
33
        except smtplib.SMTPException as e:
-
 
34
            print e
12
    
35
    
13
    def sendMail(self, mail):
36
    def sendMail(self, mail):
14
        if mail.sender:
37
        if mail.sender:
15
            mail.data = "This mail is sent by " + mail.sender + "\n" + mail.data
38
            mail.data = "This mail is sent by " + mail.sender + "\n" + mail.data
16
        
39
        
Line 23... Line 46...
23
            msg['From'] = mail.sender
46
            msg['From'] = mail.sender
24
        else:
47
        else:
25
            msg['From'] = "help@saholic.com"
48
            msg['From'] = "help@saholic.com"
26
        msg['Subject'] = mail.subject
49
        msg['Subject'] = mail.subject
27
        
50
        
28
        mail.sender = "help@shop2020.in"
-
 
29
        mail.password = "5h0p2o2o"
-
 
30
        mailServer = smtplib.SMTP("smtp.gmail.com", 587)
-
 
31
        mailServer.ehlo()
-
 
32
        mailServer.starttls()
-
 
33
        mailServer.ehlo()
-
 
34
        mailServer.login(mail.sender, mail.password)
-
 
35
        rs = mailServer.sendmail(mail.password, [mail.to], msg.as_string())
51
        rs = self.mailServer.sendmail(self.password, [mail.to], msg.as_string())
36
        # Should be mailServer.quit(), but that crashes...
52
        # Should be mailServer.quit(), but that crashes...
37
        mailServer.close()
-
 
38
        return rs
53
        return rs
39
 
54
 
40
    def send(self):
55
    def send(self):
41
        print "Despatch stared at ", time.time()
56
        print "Despatch stared at ", time.time()
42
        helper_client = HelperClient().get_client()
57
        helper_client = HelperClient().get_client()