-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsendMail.py
33 lines (27 loc) · 957 Bytes
/
sendMail.py
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
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import config
class mailer:
body =""
def __init__(self, subject, body):
self.subject = subject
self.body = body
def SendMail(self):
fromaddr = config.conf['fromEmail']
toaddr = config.conf['toEmail']
password = config.conf['password']
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = self.subject
body = self.body
# plain may be more practical. But with html we could use more fancier template for newsletter.
msg.attach(MIMEText(body, 'plain'))
#msg.attach(MIMEText(body, 'html'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, password)
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()