ich versuche gerade eine automatisch generierte E-Mail beim erstellen von JPG-Daten zu versenden. Dazu benutze ich das Modul "simplemail".
Leider erhalte ich folgende Fehlermeldung, mit der ich nichts anfangen kann:
Code: Alles auswählen
Traceback (most recent call last):
File "MyWatch.py", line 8, in <module>
myemail = simplemail.Email(
AttributeError: 'module' object has no attribute 'Email'
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import pyinotify
import time
import simplemail
myemail = simplemail.Email(
smtp_server = "smtp.gmail.com",
smtp_user = "ts***@gmail.com",
smtp_password = "***"
)
wm = pyinotify.WatchManager() # Watch Manager
mask = pyinotify.IN_CREATE # watched events
def PrepareMail(myattach):
myemail.from_address = "ts***@gmail.com"
myemail.from_caption = "From Caption?!"
# Empfaenger
myemail.recipients.add("ts***@gmail.com", "Thomas S.")
# Betreff
myemail.subject = "Motiontracking - ALERT - ", time.strftime("%d,%m,%y %H:%M:%S")
# Nachricht
myemail.message = \
"Das ist eine automatische E-Mail von Raspberry Pi 3 B\n" + \
"\n" + \
"Ein Ereignis der Webcam wurde ausgelöst.\n" + \
"Das entsprechende Bild ist im Anhang beigefügt.\n" + \
"\n" + \
"\n" + \
"\n" + \
""
# Anhaenge
myemail.attachments.add_filename(myattach)
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
print ("Creating:", event.pathname)
if os.path.splitext(event.pathname)[1] == '.jpg':
print("JPG gefunden")
PrepareMail(event.pathname)
if myemail.send():
print ("E-Mail wurde gesendet")
else:
print ("E-Mail konnte nicht gesendet werden")
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch('/home/thomas', mask, rec=True)
notifier.loop()
Auf was deutet diese Fehlermeldung hin???