""" Python Script zum Automatischen versenden von Daten --- Licend under GPLv3 see http://www.gnu.org/licenses/gpl-3.0.de.html --- File written 02.08.2011 from Martin Fink, Autohaus Dresen GmbH --- Version: 0.93b (Testingphase) --- Last Change: 23.01.2012 Martin Fink """ # Info:no shebang da das Script fuer Windows geschrieben ist! # Librabryimports import smtplib import base64 ### Konfiguration attachfile = "C:\GAPS\Portal\System\IQD\Serv_Teile\Schnittstelle_Service.csv" attachfilename = "Schnittstelle_Service.csv" # Daten auslesen. f = open(attachfile) attachdata = f.read() f.close() # base64 codierung in eigene variable. b64data = base64.b64encode(attachdata) mailserver = "mail.ahdresen.de" mailfrom = "\"noreply@dresen.de\"" mailto = "\"kuzuf_dresen@resultnetworks.de\"" # Live mailto2 = "\"ekg@dresen.de\"" # Kontrolle mailbody = "siehe Anhang" marker = "DR3S3N4711MAILMARKER" # Mailheader mailheader = """From:%s To:%s To:%s Subject: Dresen Datenexport EKG MIME-Version: 1.0 Content-Type: multipart/mixed; Boundary=%s --%s """ % (mailfrom, mailto, mailto2, marker, marker) # Messagebody messagebody = """Content-Type: text/plain Content-Transfer-Encoding:8bit %s --%s """ % (mailbody, marker) # Attachmentsection messageattach = """Content-Type: text/csv; charset=ISO-8859-15; name=\"%s\" Content-Transfer-Encoding:base64 Content-Disposition: attachment; filename=%s %s --%s-- """ % (attachfilename, attachfilename, b64data, marker) # attachdata fuer utf8 und b64data fuer base64 # message bauen message = mailheader + messagebody + messageattach # mail zur kontrolle printen: # print message # Mail versenden smtp = smtplib.SMTP(mailserver) smtp.sendmail(mailfrom, [mailto, mailto2] , message) smtp.close()