<p>所以我改变了readLastLog的返回值,做了一个单独的函数,
不管怎样,这还没有解决问题,所以这里的问题可能是我的@网站.de邮件。
与其他电子邮件一起更改为自己的邮件服务器。现在我确实收到电子邮件了。
抱歉耽误了你的时间。你知道吗</p>
<pre><code>def readLastLog():
log=open('log', 'r')
for line in log:
lastlog= line
print (lastlog)
log.close()
return lastlog
def sende():
import smtplib
import configparser
from email.message import Message
config = configparser.ConfigParser()
config.read('config.ini')
absender=(config['SMTP']['absender'])
password=(config['SMTP']['password'])
empfaenger=(config['SMTP']['empfaenger'])
smtphost=(config['SMTP']['smtphost'])
port=int(config['SMTP']['port'])
#check for if variables is correct
print("Email Config:")
print(absender, '\n',empfaenger,'\n',smtphost,'\n',port)
server = smtplib.SMTP_SSL(host=smtphost, port=port)
#do I need realy need this?
#server.esmtp_features['auth'] = 'LOGIN PLAIN'
nachricht = Message()
nachricht.set_payload(readLastLog())
nachricht["Subject"] = "Kritische Warnung - Hardlimit erreicht"
nachricht["FROM"] = absender
nachricht["To"] = empfaenger
server.login(absender, password)
server.sendmail(absender, empfaenger, nachricht.as_string())
server.quit()
</code></pre>