Added Mail Send to locklist
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/python3
|
||||
import poplib, email, os
|
||||
import smtplib
|
||||
from DB import *
|
||||
from time import time, strftime
|
||||
|
||||
def mail_connection (server = 'pop3.strato.de'):
|
||||
pop_conn = poplib.POP3_SSL (server)
|
||||
@@ -8,6 +10,23 @@ def mail_connection (server = 'pop3.strato.de'):
|
||||
pop_conn.pass_('v!mejuq5334066')
|
||||
return pop_conn
|
||||
|
||||
|
||||
def sendstatus_mail (status, msgtext):
|
||||
from email.mime.text import MIMEText
|
||||
# Create a text/plain message
|
||||
msg = MIMEText (msgtext)
|
||||
msg['Subject'] = 'FINOBA-BY gotlocklist %s' % status
|
||||
msg['From'] = 'tragstruktur.sperrdatei@finoba-bavaria.de'
|
||||
msg['To'] = 'admin@mir.systems'
|
||||
|
||||
print ('Conn')
|
||||
s = smtplib.SMTP_SSL('smtp.strato.de')
|
||||
print ('login')
|
||||
s.login ('tragstruktur.sperrdatei@finoba-bavaria.de', 'v!mejuq5334066')
|
||||
print ('send')
|
||||
s.send_message(msg)
|
||||
s.quit()
|
||||
|
||||
def updatelockist (dbconn = None, delete_after = False):
|
||||
pop_conn = mail_connection ()
|
||||
messages = [pop_conn.retr (i) for i in range (1, len ( pop_conn.list ()[1]) + 1)]
|
||||
@@ -21,8 +40,8 @@ def updatelockist (dbconn = None, delete_after = False):
|
||||
for part in mail.walk():
|
||||
if part.get_content_type () in ('text/csv', 'text/plain'):
|
||||
filename = part.get_filename ()
|
||||
print (filename)
|
||||
if filename and not '/' in filename:
|
||||
filename = strftime ("%Y-%m-%d_%H%M%S_") + filename
|
||||
#Attack protection
|
||||
fp = open (os.path.join ('/srv/lockfiles', filename), 'wb')
|
||||
fp.write (part.get_payload (decode = 1))
|
||||
@@ -64,5 +83,6 @@ def updatelockist (dbconn = None, delete_after = False):
|
||||
pop_conn.quit ()
|
||||
|
||||
if __name__ == "__main__":
|
||||
#sendstatus_mail ('Test', 'Testmtex')
|
||||
conn = DB ('/opt/data/bde.sqlite', '/tmp/talog.sql', logtest, errlogtest)
|
||||
updatelockist (conn, delete_after = True)
|
||||
|
||||
Reference in New Issue
Block a user