Advertisement
themlruts

Untitled

Nov 11th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import imaplib
  2. import email
  3. import re
  4. import _mssql
  5.  
  6. conn = _mssql.connect(server='name', user='user', password='pw', database='db')
  7.  
  8. m = imaplib.IMAP4_SSL("imap.gmail.com", 993)
  9. m.login("user","pw")
  10. m.select('"Fire_Dispatch"')
  11.  
  12. result, data = m.search(None, "ALL") # search all email and return uids
  13. if result == 'OK':
  14.     for num in data[0].split():
  15.         result, data = m.fetch(num,"(BODY[TEXT])")
  16.         if result == 'OK':
  17.             email_message = email.message_from_string(data[0][1].decode('utf-8'))    # raw email text including headers
  18. p = str(email_message)
  19. a = re.search("ALLCFD(.*)",p)
  20.  
  21. t =  (a.groups(1))
  22.  
  23.  
  24. conn = _mssql.connect(server='localhost', user='username', password='password', database='db name')
  25.  
  26. conn.execute_non_query("INSERT INTO calls (call_date_time,call)VALUES(123,'t')")
  27.  
  28.            
  29. m.close()
  30. m.logout()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement