mailer-ekg.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """ Python Script zum Automatischen versenden von Daten
  2. --- Licend under GPLv3 see http://www.gnu.org/licenses/gpl-3.0.de.html
  3. --- File written 02.08.2011 from Martin Fink, Autohaus Dresen GmbH
  4. --- Version: 0.93b (Testingphase)
  5. --- Last Change: 23.01.2012 Martin Fink
  6. """
  7. # Info:no shebang da das Script fuer Windows geschrieben ist!
  8. # Librabryimports
  9. import smtplib
  10. import base64
  11. ### Konfiguration
  12. attachfile = "C:\GAPS\Portal\System\IQD\Serv_Teile\Schnittstelle_Service.csv"
  13. attachfilename = "Schnittstelle_Service.csv"
  14. # Daten auslesen.
  15. f = open(attachfile)
  16. attachdata = f.read()
  17. f.close()
  18. # base64 codierung in eigene variable.
  19. b64data = base64.b64encode(attachdata)
  20. mailserver = "mail.ahdresen.de"
  21. mailfrom = "\"noreply@dresen.de\""
  22. mailto = "\"kuzuf_dresen@resultnetworks.de\"" # Live
  23. mailto2 = "\"ekg@dresen.de\"" # Kontrolle
  24. mailbody = "siehe Anhang"
  25. marker = "DR3S3N4711MAILMARKER"
  26. # Mailheader
  27. mailheader = """From:%s
  28. To:%s
  29. To:%s
  30. Subject: Dresen Datenexport EKG
  31. MIME-Version: 1.0
  32. Content-Type: multipart/mixed; Boundary=%s
  33. --%s
  34. """ % (mailfrom, mailto, mailto2, marker, marker)
  35. # Messagebody
  36. messagebody = """Content-Type: text/plain
  37. Content-Transfer-Encoding:8bit
  38. %s
  39. --%s
  40. """ % (mailbody, marker)
  41. # Attachmentsection
  42. messageattach = """Content-Type: text/csv; charset=ISO-8859-15; name=\"%s\"
  43. Content-Transfer-Encoding:base64
  44. Content-Disposition: attachment; filename=%s
  45. %s
  46. --%s--
  47. """ % (attachfilename, attachfilename, b64data, marker) # attachdata fuer utf8 und b64data fuer base64
  48. # message bauen
  49. message = mailheader + messagebody + messageattach
  50. # mail zur kontrolle printen:
  51. # print message
  52. # Mail versenden
  53. smtp = smtplib.SMTP(mailserver)
  54. smtp.sendmail(mailfrom, [mailto, mailto2] , message)
  55. smtp.close()