forked from basking-in-the-sun2000/solar-logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemails.py
38 lines (29 loc) · 858 Bytes
/
emails.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
33
34
35
36
37
38
import smtplib
import time
import config
message_str = """\
From: %s <data-logger>
To: <%s>
Subject: %s
MIME-Version: 1.0
Content-Type: text/html
Date: %s
%s
</br>
"""
def send_mail(content):
global message_str
if config.email_sent == content:
return
config.email_sent = content
subject = "Solar logger reporting"
message = message_str % (config.fromaddr, config.toaddrs, subject, time.strftime("%a, %-d %b %Y %H:%M:%S %z"), content)
try:
server = smtplib.SMTP_SSL(host=config.mail_server, port=config.mail_port)
if config.debug:
server.set_debuglevel(1)
server.login(config.fromaddr, config.mail_pass)
server.sendmail(config.fromaddr, config.toaddrs, message)
server.quit
except Exception as e:
print("mailing error: %s" % str(e))