blob: d3edfb85e976f5e07d6d15fcb3812ee7e80e225b (
plain)
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
|
import smtplib
from email.mime.text import MIMEText
from email.utils import formatdate
from config import config
def send(frm, name, to, subject, body, subtype="plain"):
"""Send a email to the given address, from the given address and name with the subject and body
"""
try:
server = smtplib.SMTP(config["email"]["server"], int(config["email"]["port"]))
server.ehlo()
server.starttls()
server.login(config["email"]["user"], config["email"]["pass"])
frm = "%s <%s>" % (name, frm)
e = MIMEText(body, subtype)
e['Subject'] = subject
e['From'] = frm
e['To'] = to
e.add_header('Date', formatdate())
server.sendmail(frm, to, e.as_string())
except Exception as e:
print("error")
print(e)
|