Guest User

Untitled

a guest
Mar 2nd, 2018
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. # Subject
  2. now = dt.datetime.now().ctime()
  3. subject = 'Change to system on %s' % now
  4.  
  5. # Body
  6. body = 'Subject: %s,n' % subject
  7. body += 'On %s, a change to the system was detected. Details follow.nn' % now
  8.  
  9. relevantFiles = list(set([x.file for x in relevantChunks]))
  10. for file in relevantFiles:
  11.  
  12. fileChunks = [x for x in relevantChunks if x.file == file]
  13. for chunk in fileChunks:
  14. body += '****** Affected file %s. ' % chunk.file
  15. <some other stuff>
  16.  
  17. server = smtp.SMTP(args.host) # host = smtp.gmail.com:<port> look this bit up
  18. server.starttls()
  19. server.login(args.username, args.password)
  20. server.sendmail(args.sender, args.recipient, body)
  21. server.quit()
  22.  
  23. from email.mime.text import MIMEText
  24. import smtplib
  25.  
  26. msg = MIMEText("Hello There!")
  27.  
  28. msg['Subject'] = 'A Test Message'
  29. msg['From'] = 'username@gmail.com'
  30. msg['To'] = 'username@gmail.com'
  31.  
  32. s = smtplib.SMTP('smtp.gmail.com:587')
  33. s.starttls() ##Must start TLS session to port 587 on the gmail server
  34. s.login('username', 'passsword') ##Must pass args gmail username & password in quotes to authenticate on gmail
  35. s.sendmail('username@gmail.com',['username@gmail.com'],msg.as_string())
  36.  
  37. print("Message Sent")
Add Comment
Please, Sign In to add comment