-
Notifications
You must be signed in to change notification settings - Fork 0
/
flogger_email_msg.py
39 lines (35 loc) · 1.18 KB
/
flogger_email_msg.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
39
import smtplib
import base64
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email import encoders
from __builtin__ import file
import settings
import os
import datetime
def email_msg(sender, receiver, msg, date, settings):
# print "Send take off msg"
if settings.FLOGGER_TAKEOFF_EMAIL != "y" and settings.FLOGGER_TAKEOFF_EMAIL != "Y":
# Don't send take off email msg
return
# body = "Msg from %s. %s taken off @ %s" % (settings.APRS_USER, msg, date)
body = "%s. %s taken off @ %s" % (settings.APRS_USER, msg, date)
print body
msg = MIMEMultipart()
msg.attach(MIMEText(body, 'plain'))
fromaddr = sender
toaddr = receiver
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = body
server = smtplib.SMTP(settings.FLOGGER_SMTP_SERVER_URL, settings.FLOGGER_SMTP_SERVER_PORT)
text = msg.as_string()
# print "Msg string is: ", text
try:
server.sendmail(fromaddr, toaddr, text)
except Exception as e:
print "Send email_msg failed, reason: ", e
server.quit()
return