Repository navigation
Expand file tree
/
Copy pathsendmail245.py
More file actions
51 lines (43 loc) · 1.42 KB
/
Copy pathsendmail245.py
File metadata and controls
51 lines (43 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# Email notification
# Contributor:
# pseudokool <pseudokool@gmail.com>
#!/usr/bin/env python
# Email notification
# Contributor:
# pseudokool <pseudokool@gmail.com>
import config
import smtplib
#from email.mime.text import MIMEText
#from email.MIMEMultipart import MIMEMultipart
#from email.header import Header
#from email.utils import formataddr
class SendMail:
def __init__(self, to, subject, msg):
self.server = smtplib.SMTP()
self.server.set_debuglevel(True)
self.smtp_username = config.app_config['smtp_username']
self.smtp_password = config.app_config['smtp_password']
# address setup
print msg
self.email_to = to
self.email_from = config.app_config['from_email']
# email body
# email body
self.email_msg = "\r\n".join([
"From: " + config.app_config['from_name'] + " <" + config.app_config['from_email'] + ">",
"To: " + config.app_config['to_email'],
"Subject: " + subject,
"",
msg
])
def do_send(self):
print 'do_send'
# initialize smtp
self.server.connect(config.app_config['smtp_host'])
self.server.ehlo()
self.server.starttls()
self.server.ehlo()
self.server.login(self.smtp_username, self.smtp_password)
self.server.sendmail(self.email_from, self.email_to, self.email_msg)
self.server.quit()